Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReSharper 2020.2.4 fails on C# 9.0 records

I'm playing with a new record feature in a console app. I'm using my VS Community 16.8.0 + R# 2020.2.4 trial.

C# code

using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var test = new Person("firstname", "lastname");
            Console.WriteLine($"test.FirstName: {test.FirstName} test.LastName: {test.LastName}");
        }
    }

    public record Person(string FirstName, string LastName);
}

Csproj file

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

</Project>

The code could be compiled and it runs.

C# 9.0 record issue

Problem

The thing is that IntelliSense does not recognise the record itself. VS underlines the record definition and does not recognise its use despite the fact that the program itself can be compiled.

What am I doing wrong?

Intellisense fails

Note

VS somehow recognise a typo in record definition/use.

Typo is recognised

like image 512
KUTlime Avatar asked Nov 12 '20 16:11

KUTlime


2 Answers

ReSharper 2020.2.4 does not support the new C# 9 features. Try the latest version (2020.3). Any further issues you have with ReSharper should best be taken up with JetBrains directly.

like image 160
Piers Myers Avatar answered Nov 09 '22 09:11

Piers Myers


I have the same "problem", I should say?

ReSharper still does not get it. Records are still broken as hell for ReSharper. As long as this goes, I cannot use ReSharper in classes where records are defined or used. Too many false errors. Switching ReSharper on and off depending on the file is ridiculously annoying, which leads to mostly ReSharper deactivated. Damn. Why the heck. I also completely removed everything ReSharper related and did a clean install again. Same result with the newest version. C# (preview) can be used since months and they still did not get it managed. Wow.

@KUTlime go to "extensions" menu and select ReSharper, then to "options...". Second way of doing this is right click the black circle at the bottom right corner and click "Customize...", there you go.

Edit: Upgrading to 2020.3 EAP7 (Early Access Preview) solved the issue for me (and the preview is slower than before).

like image 38
CleanCoder Avatar answered Nov 09 '22 09:11

CleanCoder