Vs2019.9.2 对未定义变量使用属性模式时引发运行时错误并且编译失败,这是预期的编译错误

问题描述

使用 2019.9.2(或 2019.9.0):

创建一个控制台 net5 应用程序。 添加一个类:

 BottomNavigationBar(
      onTap: (value) {
        if (value == 0) Navigator.of(context).push(...);
        if (value == 1) Navigator.of(context).push(...);
        if (value == 2) Navigator.of(context).push(...);
      },),

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

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

如下图所示:

vs2019 error

并且你不能删除这些错误,那么vs2019会引发编译错误

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.

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

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  

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

删除属性模式检查并将上面的行替换为下一行:

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

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)