I created a small Record type in C#:
However the compiler didn’t like it:
Why? Because I was adding this code to a .NET Standard 2.0 library that doesn’t support C# 9 features.
As a reminder, a small overview:
Target framework Version | C# Language Version |
.NET 5 | C# 9.0 |
.NET Core 3.x | C# 8.0 |
.NET Core 2.x | C# 7.3 |
.NET Standard 2.1 | C# 8.0 |
.NET Standard 2.0 | C# 7.3 |
I didn’t want to upgrade to .NET 5 so what are my options? Turns out, that you can work around this with a small compiler hack…
Let’s try it:
- First you need to override the language version in the csproj file:
- Then you should add the following code to get rid of the compiler error: