Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Support for C# 9.0 in Visual Studio

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; }
}

Error Screenshot


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>

Visual Studio Version

Visual Studio Version

Installed SDKs

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]

Proof that it's running .NET 5.

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.

enter image description here

like image 685
El Mac Avatar asked Nov 11 '20 15:11

El Mac


People also ask

How do I know if G ++ supports C++17?

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.

Is C++20 supported?

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.

Does GCC 4.8 support C++17?

GCC has had complete support for C++17 language features since version 8.

Is C++20 released?

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).


2 Answers

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.


Update

Resharper 2020.3 and Rider 2020.3 are released now and officially support .NET 5 and C# 9.

like image 108
El Mac Avatar answered Sep 27 '22 17:09

El Mac


You need to use ReSharper 2020.3 for it to work with .NET 5 and C# 9.0.

like image 22
Piers Myers Avatar answered Sep 27 '22 18:09

Piers Myers