question

christianokiss avatar image
0 Votes"
christianokiss asked christianokiss commented

Nullable option disabled in Project properties

I was doing some experimentation with C# 8's Nullable References Types and came across this issue:

None of the projects allow changing the "Nullable" option within the project's properties window. Some of the projects have that option enabled and others don't even declare it, which probably assumes "disabled" by default.

I can set it manually via the *.csproj file using the <Nullable>enable</Nullable> option, of course.

I also couldn't find a Directory.Build.props, in case that would impact.

I just wanted to understand why the option is greyed out in Visual Studio's UI when opening the project properties window (tab Build, below the "Platform target" option).

Thanks in advance

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

TimonYang-MSFT avatar image
0 Votes"
TimonYang-MSFT answered christianokiss commented

Are you using .Net Core and which version?

C# language versioning

In my test, if I use .Net Core 3.x or .Net 5, this option is available.

96156-1.png


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1.png (8.7 KiB)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am using .NET 5.

Yep, that's precisely the option that appears greyed out for me. It's a solution with other projects as well, they all behave the same.

Curiously, some of the projects have that option enabled in the *.csproj, so the UI presents it greyed out but with the "Enable" value.

If I create a solution from scratch with multiple projects, I can change the Nullable switch just fine. So, it's probably something to do with that other particular solution.

0 Votes 0 ·

Did the solution with this problem written by you?
I have done many tests, but only when the .Net Core version is lower than 3.0 can it be grayed out.
Moreover, if I add <Nullable>enable</Nullable> to csproj file, it will indeed be grayed out with Enable value, everything is the same as you described.
In addition to this possibility, I did not find other probable causes of this phenomenon so for.

0 Votes 0 ·

I didn't write the solution myself.

I can't reproduce it with a brand new solution. I was wondering if there's some sort of a global configuration somewhere that could cause this behaviour?

Anyway, I think it's a good UI practice to add some explanation why the option is disabled when the user hovers the mouse over it. If Visual Studio provided this information, I wouldn't need to try to figure out why the setting is greyed out. :)

0 Votes 0 ·

Well, I haven't found such a configuration so far.
And I consulted a colleague who is familiar with Visual Studio, and the result is that there is no way to do this. You may need to contact the author of this solution and ask him what he did.

I think it's a good UI practice to add some explanation why the option is disabled when the user hovers the mouse over it

You can request this feature in the Developer Community.
The Visual Studio team will monitor this site, your feature request may be added to Visual Studio in a future version.

1 Vote 1 ·