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

TL;DR

In order to allow nullable reference types, upgrade your project to .NET Standard 2.1 which defaults to using C# 8.0. - https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version

Background

An issue arose in our Team City build server, where JetBrains' inspectcode.exe reported CSharpWarnings::CS8632 (The annotation for nullable reference types should only be used in code within a '#nullable' annotations context) although we'd enabled the nullable context in our .targets file and although Visual Studio didn't complain.

After some digging around, we found that we were building against the .NET Standard 2.0 framework, whereas the C# 8 features that we were reaching for, requires .NET Standard 2.1. After an upgrade, inspectcode.exe happily accepted our nullable annotations and let our code through the rest of the build pipeline.

Comments

Popular posts from this blog

Auto Mapper and Record Types - will they blend?

Unit testing your Azure functions - part 2: Queues and Blobs

Testing WCF services with user credentials and binary endpoints