Unexpected compilation diagnostic when compiling with Roslyn

Viewed 79

I have a solution which uses C#8 nullable reference types and has <Nullable>enable</Nullable> in a csproj property group. Everything compiles in VisualStudio and on the command line without warnings or errors.

However, when I load the same solution using Roslyn with MSBuildWorkspace, I see dozens of the following project-level diagnostic:

error CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

I would not expect to see this error because the same solution compiles without warnings/errors in Visual Studio (which respects the csproj setting that enables #nullable).

What would cause Roslyn to ignore the <Nullable>enable</Nullable> in the csproj?

0 Answers
Related