首页 > 解决方案 > 在 Visual Studio 2019 中调试元组函数 C#9/.NET 5.0 时出现 ExecutionEngineException

问题描述

我在安装了 .NET Framework 4.8.04084 和 .NET Core 5.0.100 并运行 .NET 5/C#9 控制台项目的 Visual Studio 16.8.1 中遇到了一个非常奇怪但可重现的异常。

以下代码:

using System;

namespace DebuggerTest
{
    class Program
    {
        static void Main(string[] args)
        {
            FunctionWithTuple();
            FunctionWithoutTuple();
        }

        static (string foo, int bar) FunctionWithTuple()
        {
            return ("", 5);
        }

        static string FunctionWithoutTuple()
        {
            return "";
        }
    }
}

当我在两个函数中添加断点时FunctionWith(out)Tuple(),让程序运行并编辑函数,例如通过添加Console.WriteLine("Hello");,我希望 Visual Studio 能够执行 WriteLine 并继续执行。但是我的经验是,将语句添加到非元组函数中,它可以工作,但是将其添加到元组返回函数中会引发错误An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module.

我在网上搜索了这个错误,但只找到了关于旧 VS 版本和与位不兼容等的内容。我找到了一个Debugging > Use Managed Compatibility Mode可以解决问题的来源。它不适合我。较低的 .NET-Core 项目版本也会出现同样的问题。(例如 .net 核心 3.1)

这是它的样子,当它失败时: 视觉工作室出现错误

.csproj 是

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

</Project>

有任何想法吗?

标签: c#visual-studiodebugging.net-corevisual-studio-2019

解决方案


推荐阅读