微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。