Break the debugger on assertion failed

2020-07-02 12:17发布

问题:

Is there a way to break the debugger when assertion is false and running the application using Visual Studio debugger. Earlier when I was debugging Windows application I would get an exception and the debugger would break, but now on Smart Device an assertion failed window is showed with stack trace, but I would also like to see variable values etc.

回答1:

Stupid me, the solution was simple. When the window pops out, press pause in debugger :)



回答2:

Not sure about VS 2008, but in at least 2010 and later, you can go to Debug/Exceptions (Ctrl-Alt-E). Click the "Add" button, choose "Common Language Runtime Exceptions", and type:

Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException

and hit "OK". It will now appear on the list, make sure you check the checkbox in the "Thrown" column. You will now get a break on any assert failure.

Updated: screenshot from VS 2017



回答3:

In addition to Vinay's solution, you can start the debugger for a specific process by calling

Debugger.Break

In your case you could do it every time the listener receives a failure message.



回答4:

It seems that you can attach the Debugger when assertion fails to see other details - see this article: http://blogs.msdn.com/b/davidklinems/archive/2005/08/29/457847.aspx. Its quite dated but perhaps still applicable.