Roslyn: #pragma warning disable nullable does not disable warning

Created on 26 Sep 2019  路  3Comments  路  Source: dotnet/roslyn

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:

https://developercommunity.visualstudio.com/content/problem/745884/vs-for-mac-does-not-respect-pragma-warning-nullabl.html

  1. .NET Standard project with:
        <LangVersion>8.0</LangVersion>
        <Nullable>enable</Nullable>
  1. Add a public property to a class in the project.
  2. Warnings about a non-nullable property shown in the editor.
  3. Add a pragma to disable the check.
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.

Area-Compilers Documentation

Most helpful comment

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

All 3 comments

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!

Was this page helpful?
0 / 5 - 0 ratings