Vs2019.9.2 Raise runtime errors when using Property Pattern for undefined variable and fail compilation and it's expected compilation error

Viewed 2253

Using Vs 2019.9.2 (or v 2019.9.0):

Create a console net5 application. Add the next class:

class Class1
    {
        public void Test1()
        {
           if (shape is Circle { Radius: >= 100 })  //variable shape is un defined, cause many errors by vs 2019.9.2
            {
                // this is a huge circle
            }
        }
    }
    public class Circle
    {
        public double Radius { get; init; }
    }

You get many error messages (without compilation) at the upper screen under the menu with these common errors:

Feature 'Diagnostic analyzer runner' is currently unavailable due to an internal error. Show Stack Trace 
Feature 'CodeLens references' is currently unavailable due to an internal error. Show Stack Trace 
Feature 'Semantic classification cache' is currently unavailable due to an internal error. Show Stack Trace 

The common error message in Stack Trace:

RPC server exception:
System.InvalidOperationException: Operation is not valid due to the current state of the object.

as shown in the next figure:

vs2019 error

and you can't remove these errors, then vs2019 raise the compilation error:

Error   MSB6006 "csc.exe" exited with code -2146232797. Vs2019Bug   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets  71  

The line ( with undefined variable shape)

if (shape is Circle { Radius: >= 100 })

cause these errors, and it's expected that vs 2019 raise a compilation error.

Remove the Property Patten check and replace the above line with the next one:

if (shape is Circle ) //cause compilation error as expected

What I missed to avoid the VS2019 runtime error?

1 Answers

I have posted the issue to the Roslyn Project here

It was reported as a bug and the issue is resolved by Roslyn Team in the next version of Vs 2019.

Thanks to Roslyn team.

Related