Debugging a new 64-bit Windows WinForms application in Visual Studio 2010? You might find unhandled exceptions aren't triggering the debugger. This is due to the wow64 emulation layer, which intercepts exceptions in code responding to 64-bit window manager notifications (like the Form1_Load
event).
Root Cause and Impact
The problem stems from Windows' inability to correctly handle exceptions moving from 32-bit (your app) to 64-bit (the notification source) code. This makes debugging difficult as the exception is invisible to the debugger.
Solutions
Here are several ways to address this:
Load
Event in try/catch
: Enclose your Load
event handler code in a try/catch
block. Use Environment.FailFast()
in the catch
block for a controlled crash with a detailed report.UnhandledExceptionMode
: In your Main()
method, call Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
to prevent the message loop from suppressing the exception during debugging.Load
Event Usage: Consider if the Load
event handler truly needs all its code. Moving some actions to the constructor might help.These solutions don't fix the underlying problem, but they provide practical ways to debug unhandled exceptions in this scenario.
The above is the detailed content of Why Are Unhandled Exceptions Missing in My 64-bit VS2010 WinForms Application?. For more information, please follow other related articles on the PHP Chinese website!