I'm using Visual Studio 2010 to write a .NET assertion:
Debug.Assert(false, "Testing Debug.Assert");
When I put a breakpoint on this line of code, wait until the breakpoint hits, and then let the program continue to run, everything works fine: an "Assertion Failed" dialog pops up. However, when I remove the breakpoint and rerun the application, the Debug.Assert() statement is simply ignored.
Does anyone have an idea what might cause this very strange behavior?
A colleague of mine immediately knew what the problem was. I had to enable the "Enable Just My Code" flag at "Visual Studio 2010 / Menu / Options / Debugging / General". Apparently this is a bug in Visual Studio 2010".
I was experiencing the same problem. Using Trace.Assert
works as expected.
Well, Trace.Assert
started exhibiting the same behavior on the next debugging session.
Ah, found the problem.
With 'Enable Just My Code" checked.
If 'Thrown' is checked for 'Common Language Runtime Exceptions' in the 'Exceptions' dialog (Ctrl+Alt+E), the Assert will be thrown.
If unchecked, the Assert will be thrown.
With 'Enable Just My Code" unchecked.
If 'Thrown' checked, the Assert will not be thrown.
If 'Thrown' unchecked, the Assert will be thrown.
Therefore, the Assert will not be thrown when 'Enable Just My Code' is unchecked and 'Thrown' is checked for 'Common Language Runtime Exceptions'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With