Version Used:
VS Mac 8.3.0 - Roslyn 3.3.1-beta3-19454-05
VS Win 16.3
Steps to Reproduce:
Posted on the Developer Community forum:
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
public class Class1
{
#pragma warning disable nullable
public string Foo { get; set; }
#pragma warning restore nullable
}
Expected Behavior:
The documentation indicates that this feature is available and should remove the warning shown in the text editor.
https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references#nullable-contexts
Actual Behavior:
The warning about the non-nullable property is still shown in the text editor.
Using `#nullable disable' at the top of the file works.
Using the code CS8618 instead of nullable in the disable pragma also works.
There are a few existing Roslyn issues which are possibly related:
https://github.com/dotnet/roslyn/issues/36550
https://github.com/dotnet/roslyn/issues/35747
Not sure if the documentation is incorrect here.
Looks like the documentation is incorrect.
As far as I know, the syntax for disabling/enabling/restoring nullable warnings is:
#nullable disable warnings
#nullable enable warnings
#nullable restore warnings
@Leemyy's comment is correct. Support for #pragma warning disable nullable was removed before releasing C# 8.0 and was replaced with #nullable disable warnings.
Submitted a PR to fix the docs: https://github.com/dotnet/docs/pull/14700
I'll go ahead and close the present issue. Thanks for reporting this!
Most helpful comment
Looks like the documentation is incorrect.
As far as I know, the syntax for disabling/enabling/restoring nullable warnings is: