Skip to content

NoWarn is not respected in nullability analysis #35730

@cartermp

Description

@cartermp

Consider this program:

using System;

#nullable enable

namespace NullnessExample
{
    class Program
    {
        public void M(string? theString)
        {
            // In the project file, this warning code is suppressed, but the nowarn is ignored.
            Console.WriteLine($"Length is {theString.Length}");
        }
        static void Main(string[] args)
        {
            // Explicitly trigger a warning here, note that is gets suppressed
            while (false) { Console.Write(""); }

            Console.WriteLine("Hello World!");
        }
    }
}

And a corresponding project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <LangVersion>8.0</LangVersion>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <NoWarn>1701;1702; 8602; 0162</NoWarn>
  </PropertyGroup>

</Project>

Expected

No nullability warning.

Actual

The CS8602 warning is still emitted.

The CS0162 warning, by comparison, is correctly suppressed.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions