当Debug.Assert失败时,导致VS2010调试器中断 [英] Causing VS2010 debugger to break when Debug.Assert fails

查看:112
本文介绍了当Debug.Assert失败时,导致VS2010调试器中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Debug.Assert 的参数评估为 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.

但是在调试时,断言被记录到输出窗格中,这很容易错过;没有弹出窗口,调试器不会停止。因此: Debug.Assert 失败时,是否有任何方法可以强制Visual Studio调试器中断?

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 :我正在开发一个基于WPF的桌面应用程序。在Windows Forms应用程序中,行为似乎有所不同:在这里,调试器在 Debug.Assert 上停止。)

(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.)

编辑:请让我澄清一下:我正在寻找Debug.Assert()的替代方法,因为我的代码我使用的外部代码充满了Debug.Assert()语句。我正在寻找一种当 Debugg.Assert 失败时导致Visual Studio调试器中断的方法。 (我认为早期的VS版本可以做到这一点,并且行为在VS2010中有所改变。)

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).

推荐答案

如果通过调试表示使用进入功能,请参阅此MS对问题的解答。

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-正确,何时步入 vs-2010-and-2008

在Assert语句中使用 Step Over也可以解决问题(对我来说)。

Using "Step Over" at the Assert statement does solve the issue too (for me).

这篇关于当Debug.Assert失败时,导致VS2010调试器中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆