I want to create a static abstract member in an interface within a .NET Standard 2.1 project. Everything I’ve read says that this just requires C#11. I set the LangVersion
tag in the project file but I get the error:
CS8919 Target runtime doesn’t support static abstract members in interfaces.
I know there are some features that require additional steps (for example, see this question). Is there a package I can add or anything else I can do?
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
public interface ITest
{
static abstract int GetInt();
}
2
.Net Standard 2.1 is supposed to be compatible with .Net/.Net Core starting from 3.0. Therefore you cannot use the latest C# features available only for the latest versions of the Framework: .Net Standard 2.1
You have to use .Net Framework that supports C# 11 or use older version of C#