Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
Environment: vs 2019 v16.3.1
in c# netstandard2.0 and net451 project, I use c# 8 nulable reference with attributes.
Enable c# 8 in csproj:
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
In myclass.cs, I use AllowNullAttribute:
class My class {
[AllowNull]
public T MyValue {get;set;}
When building the project, I get a compilation error:
CS0246 The type or namespace name 'AllowNullAttribute' could not be found (are you missing a using directive or an assembly reference?) ConsoleApp1 (netstandard2.0)
The documentation Attributes extend type annotations include these types
What is wrong in this code?
–
C# 8 (and therefore, by extension, AllowNull) does not seem to be fully supported in netstandard 2.0.
For example, if you go to the documentation for AllowNull and select .NET Standard 2.0 as the version, you will get the following message:
The requested page is not available for .NET Standard 2.0. You have
been redirected to the newest product version this page is available
Also see this Github issue. Namely,
Officially, C# 8.0 is only supported on runtimes that adhere to the
.NET Standard 2.1. That does not (and will not) include .NET Framework