当Debug.Assert失败时导致VS2010调试器中断

12 c# wpf visual-studio-2010

有什么办法使Visual Studio 2010的突破而当参数调试Debug.Assert计算结果为false

示例:在我的代码中,我有这样的行:

Debug.Assert(!double.IsInfinity(x));
Run Code Online (Sandbox Code Playgroud)

如果我没有调试,则在断言失败时会弹出一个窗口.

但是当我调试时,断言被记录到"输出"窗格中,这很容易被遗漏; 没有弹出窗口,调试器不会停止.因此:有什么方法可以强制Visual Studio调试器在Debug.Assert失败时中断?

(顺便说一句:我正在开发一个基于WPF的桌面应用程序.在Windows窗体应用程序中,行为似乎不同:在这里,调试器停止运行Debug.Assert.)

编辑:请让我澄清:我不是在寻找Debug.Assert()的替代品,因为我使用的代码和外部代码充满了Debug.Assert()语句.我正在寻找一种方法来使Visual Studio调试器在Debugg.Assert失败时中断.(我认为早期的VS版本就是这样做的,并且VS2010中的行为发生了变化).

Fra*_*čik 6

如果通过调试意味着使用"Step Into"功能,请参阅此MS对问题的回答.

http://connect.microsoft.com/VisualStudio/feedback/details/522995/system-diagnostics-debug-assert-doesnt-pop-up-messagebox-correctly-when-step-into-it-in-vs-2010-和2008年

在Assert语句中使用"Step Over"确实解决了这个问题(对我而言).

  • 你提到的Connect文章让我走上正轨.我遇到的问题在这里描述:https://connect.microsoft.com/VisualStudio/feedback/details/687333/debug-assert-cannot-popup-a-dialog-in-visual-studio-in-the- wpf-project#details.这是一个VS2010的bug; 作为一种解决方法,建议打开"仅我的代码"选项. (5认同)