c# - 在 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>
有任何想法吗?
解决方案
推荐阅读
- angular - angular 8 两次加载应用程序资产
- python-3.x - python2和python3的区别
- mysql - MYSQL 从表中选择是否包含给定 IPv6 网络中的 IPv6 网络
- mysql - WordPress 自动化脚本每天同步登台和生产数据库
- c++ - 如何监控ZeroMQ服务器是否存在?
- javascript - 如何在自定义可链接 JavaScript 库中由 querySelectorAll 选择的第一个元素上调用最接近()?
- ckeditor - 如何以相同的 css 样式显示数据库中的 ckeditor 5 内容
- c# - 如何连接字符串中的对象,中间有分号?
- css - 未聚焦时如何更改选定的选项颜色?
- perl - 使用 Net::SFTP::Foreign Perl 模块在屏幕上打印远程服务器 FILENAME、MTIME