“编辑并继续”仅在使用 "Start external program" 时有效,但不适用于“附加到流程”

Edit & Continue only works when using "Start external program" but not Attach to Process

我在 C# 中有一个 Excel-DNA 项目,使用 .NET 4.0 使用 Visual Studio 2010/2015。

如果我启动调试并使用 "Start external program" 功能来启动 EXCEL.exe 我可以暂停调试器并且编辑并继续工作得很好。

但是,如果我尝试附加到 运行 EXCEL.exe 进程,我会收到一条错误消息,指出由于多种原因之一不支持“编辑并继续”。选择附加到进程时,我只选择了 "Managed (v4.6, v4.5, v4.0)"。

错误消息指出:

Changes are not allowed in the following cases:
- Attached to a process that does not support Edit and Continue on attach.
- The code being debugged was optimized.
- The assembly being debugged is loaded as domain-neutral.
- The assembly being debugged was loaded through reflection.
- Intellitrace events and call information is enabled.
- The .NET Runtime this program is running does not support edit and continue.

这两种情况有什么区别? "Start external program" 与手动附加有何不同?

这是well documented:

Edit and Continue is not available in the following debugging scenarios:

  • Debugging an application with Attach to rather than running the application with Start from the Debug menu.

您使用“启动外部程序”选项找到的解决方法是正确的方法。