调试期间代码更改 ("Edit and Continue") 后跟 Debug.SetNextStatement 时 CLR 崩溃

CLR crash when code change during debugging ("Edit and Continue") is followed by Debug.SetNextStatement

在 Visual Studio 2015 调试会话(断点命中)期间,如果我更改几乎所有代码和 select Continue 中的任何一个Step IntoStep Over(等)命令,我立即得到 ExecutionEngineException,然后是 CLR 崩溃。

这似乎只出现在一个项目中。

System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason, int pvLoopData)    Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context)    Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.ApplicationContext context)  Unknown
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() Unknown
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()    Unknown
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(string[] commandLine)   Unknown
[Native to Managed Transition]  
[Managed to Native Transition]  
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) Unknown
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()   Unknown
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state)    Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()    Unknown

如何解决这个问题?

我通过最小化问题场景找到了答案。

看起来问题出在 组合 + + 和此代码:

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim gridSize As Size = New Size(3, 11)
        Dim z As Integer
        z = 22
        z = 1
    End Sub
End Class

End Sub 处放置断点,在此停止,交换赋值并将下一条语句设置为第一个赋值。轰.

Reported to the Microsoft. Workaround is to use 及更高。

我在使用 C# 的 Visual Studio Community 2015 时遇到了同样的问题。 在调试为 .Net 3.5 编译的项目时,遇到断点并执行 'edit and continue',它很少能存活下来。 compiler/IDE 崩溃并显示几种可能的错误消息之一,最常见的是 ExecutionEngineException,然后是 CLR 崩溃。

当同一项目编译为 .net 4.6.1 时,VS 2015 IDE 调试器运行正常。主项目设置为.net 4.6.1即可;调用的 .dll 可以调试,即使它们仍然是 .net 3.5。

(旧的 VS 2013 IDE 调试器可以在 .net 3.5 上正常运行,很少崩溃。)

许多项目都存在这种行为。