How can I turn on the support for the records keyword in C# 9.0?
When I try to use the new record
keyword (or the init
), I get an unexpected token error in Visual Studio.
What am I missing? Or is C# 9.0 not supported in Visual Studio 16.8?
public record Person
{
public string? FirstName { get; init; }
public string? LastName { get; init; }
}
Update: Just read the marked answer. The information below ended up not being important for this problem and is here just for documentation purposes.
I am using Visual Studio 16.8 with the language set to 9.0
in my project file.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<LangVersion>9.0</LangVersion>
<TargetFramework>net5.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.ApiAuthorization.IdentityServer" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
</Project>
2.1.2 [C:\Program Files\dotnet\sdk]
2.1.104 [C:\Program Files\dotnet\sdk]
2.1.201 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.301 [C:\Program Files\dotnet\sdk]
2.1.400 [C:\Program Files\dotnet\sdk]
2.1.508 [C:\Program Files\dotnet\sdk]
2.1.700 [C:\Program Files\dotnet\sdk]
2.1.801 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
3.0.100 [C:\Program Files\dotnet\sdk]
3.1.201 [C:\Program Files\dotnet\sdk]
5.0.100 [C:\Program Files\dotnet\sdk]
So to make sure it's really running .NET 5, I have created a route to output the .NET runtime version. Looks like it's really running .NET 5.
C++17 Support in GCC C++17 features are available since GCC 5. This mode is the default in GCC 11; it can be explicitly selected with the -std=c++17 command-line flag, or -std=gnu++17 to enable GNU extensions as well.
Full supportVisual Studio 2019 supports all C++20 features through its /std:c++latest option, as of version 16.10. 0. An option /std:c++20 to enable C++20 mode is added in version 16.11. 0.
GCC has had complete support for C++17 language features since version 8.
C++ is standardized by the International Organization for Standardization (ISO), with the latest standard version ratified and published by ISO in December 2020 as ISO/IEC 14882:2020 (informally known as C++20).
After analyzing the loading times of the error message and receiving the same error message in the Rider IDE, I came to conclusion it had to be Resharper.
I uninstalled Resharper and the error messages disappeared.
Resharper 2020.3 and Rider 2020.3 are released now and officially support .NET 5 and C# 9.
You need to use ReSharper 2020.3 for it to work with .NET 5 and C# 9.0.
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