vs2019.9.2 使用 属性 Pattern for undefined variable 时引发运行时错误并编译失败,这是预期的编译错误

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

使用 Vs 2019.9.2(或 v 2019.9.0):

创建控制台 net5 应用程序。 添加下一个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; }
    }

您在菜单下方的屏幕上方收到许多错误消息(未经编译),其中包含以下常见错误:

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.

如下图所示:

而且你不能删除这些错误,然后vs2019引发编译错误:

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

线(具有未定义的可变形状)

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

导致这些错误,预计 vs 2019 会引发编译错误。

删除 属性 Patten 检查并将上一行替换为下一行:

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

我错过了什么来避免 VS2019 运行时错误?

我已将问题发布到 Roslyn Project here

它被报告为一个错误,Roslyn 团队在 Vs 2019 的下一版本中解决了这个问题。

感谢 Roslyn 团队。