I'm trying to use the just-released .NET Standard 2.1 C# 8.0 features in VS2019 Preview 16.4.0 but keep receiving the message "Cannot resolve symbol 'notnull'".
My example code:
class Example<T> where T : notnull {}
I have the <Nullable>enable</Nullable> and <LangVersion>8</LangVersion> property set in my project file and all of that new functionality is working great, it just seems to be this.
How can I use the notnull type contraint?
This is because C# 8.0 is not enabled.
In some preview versions of .NET Core 3.0 SDK, C# 8.0 was a preview version rather than latest or latestMajor version which is taken as the default language version.
But at least in .NET Core 3.0 GA (formal release version), C# 8.0 is enabled by default if your project targets netcoreapp3.0. But as for netstandard2.1 target, the default language version is still 7.3.
If you really need to share this library with the latest Xamarin apps that supports .NET Standard 2.1, specify <LangVersion>8.0</LangVersion> explicitly in the .csproj file within PropertyGroup, or you just set the TargetFramework to netcoreapp3.0 and C# 8.0 should be enabled by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With