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.
Break the debugger on assertion failed
12.5k views Asked by Bogi AtThere are 5 answers
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.
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.
For a Native Unit Test project (C++), we can follow a method similar to the one in @Darrel Hoffman's answer.
Go to Debug->Windows->Exception Settings
.
Add a new exception under Win32 Exceptions
.
For error code enter 0xE3530001
, and give it some description.
Now, from test explorer, select Debug
, instead of Run
.
Alternatively, it will work even if you select <All Win32 Exceptions not in this list>
.
Visual Studio will now break whenever a Native Unit Test assertion (Assert::IsTrue, Assert::IsFalse, etc.) fails.
Note that by default breaking on 0xc0000420 Assertion failed
exception is enabled in Visual Studio exception settings, however it doesn't cause the debugger to break when our unit test assertion fails, hence the steps above are necessary.
PS: @Darrel Hoffman' answer is sufficient for C# unit tests, but for native C++ a few extra steps are required, hence my answer may help those like me who stumble upon this for native use case.
References:
Stupid me, the solution was simple. When the window pops out, press pause in debugger :)