Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nullable reference types in .NET Framework projects not working with IntelliSense

When I create a new Console App (.NET Framework 4.8), and try to use C# 8's nullable reference types, I see the following:

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context

And, I get this warning in my build output:

warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Understandable, I haven't enabled nullable reference types yet. I add the following to my .csproj:

<Nullable>enable</Nullable>

This makes the build warning disappear, but Visual Studio's IntelliSense keeps complaining.

How can I configure Visual Studio so it understands I'm using nullable reference types in my .NET Framework project, without using #nullable everywhere?


In contrast, if I create a new .NET Core 3.0 Console App, everything works as expected.

like image 698
Rudey Avatar asked Sep 29 '19 11:09

Rudey


1 Answers

How can I configure Visual Studio so it understands I'm using nullable reference types in my .NET Framework project, without using #nullable everywhere?

I'm afraid the answer is negative since this could be one issue about VS Intellisense.

I found msbuild(VS build system) can recognize the C#8.0 in .net framework4.8 projects well during build process. But Intellisense(one VS feature) can't, so I've reported it. If anyone is interested in this issue, more details about the issue see Intellisense can't recognize C#8.0 in project that targets .net framework 4.8.

The behavior is that Intellisense doesn't display the correct message for us in .net framework 4.8 project with C#8.0. And this is one issue which can only be handled by the fix. So there's no valid way to resolve this issue of Intellisense(a VS feature) unless the fix comes after we report this issue. We may Suppress or Configure CS8632's severity, but it's quite a bad idea..

like image 76
LoLance Avatar answered Sep 23 '22 02:09

LoLance