Version Used:
Visual Studio 2019 16.2.3
.NET Core: 3.0.0-preview8-28405-07
Steps to Reproduce:
For CS8602 I am not getting the expected errors when I add this code in the WarningsAsErrors section.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<Nullable>enable</Nullable>
<WarningsAsErrors>CS8602</WarningsAsErrors>
</PropertyGroup>
</Project>
private static void PosibleDereferenceNullableReferenceTypes()
{
string data = null;
Console.WriteLine(data.Length);
}
Expected Behavior:
An error when we build the project.
Error CS8602 Dereference of a possibly null reference.
Note: When I put the codes CS8600, CS8603 or CS8604 into the WarningsAsErrors section, I receive the expected error messages in compilation time.
Actual Behavior:
Warning CS8602 Dereference of a possibly null reference.
If I write into the csproj:
<WarningsAsErrors>CS8600;CS8602</WarningsAsErrors>
I get the error messages for CS8600 (as expected) and for CS8602
If I change my csproj as:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>
And my application code is:
private static void PosibleDereferenceNullableReferenceTypes()
{
#nullable enable
string data = null;
Console.WriteLine(data.Length);
#nullable restore
}
Here I get the error for CS8602 as expected
For some reason, the command line build fails, but we don't get an error in the VS error list. Looking into whether there is maybe a bug in the VS workspace.
This may be an instance of dotnet/project-system#3680, but relating to the WarningsAsErrors property instead of the WarningsNotAsErrors property.
Basically, it seems like for some values of WarningsAsErrors, the project system sends us a command line with ... /warnAsError- ... /warnAsError+:CS0105 .... For other values it sends us a command line like ... /warnAsError+:CS8602 ... /warnAsError- .... The latter case is where the bug happens-- warnAsError- wins and we don't get the right behavior in the IDE.
As far as I am aware, this is a project system bug, and can't be fixed within Roslyn. /cc @davkean