Is there any way to cause Visual Studio 2010 to break while debugging when the argument of Debug.Assert evaluates to false?
Example: in my code I have lines like this:
Debug.Assert(!double.IsInfinity(x));
If I am not debugging, a window pops up when the assertion fails.
But when I am debugging, the assertion is logged to the “Output” pane, which is easy to miss; there is not popup window and the debugger does not stop. Therefore: is there any way to force the Visual Studio debugger to break when Debug.Assert fails?
(BTW: I am developing a WPF based desktop application. In a Windows Forms application, the behavior seems to be differnt: here, the debugger stops on Debug.Assert.)
EDIT: Please let me clarify: I am not looking for an alternative to Debug.Assert(), because my code and external code I use is full of Debug.Assert() statements. I am looking for a way to cause the Visual Studio debugger to break when Debugg.Assert fails. (I think earlier VS versions did that, and that the behavior changed in VS2010).
If by debugging you mean using “Step Into” feature, see this MS’s answer to the problem.
http://connect.microsoft.com/VisualStudio/feedback/details/522995/system-diagnostics-debug-assert-doesnt-pop-up-messagebox-correctly-when-step-into-it-in-vs-2010-and-2008
Using “Step Over” at the Assert statement does solve the issue too (for me).