Debug.Assert() 已停止在我的项目中工作
由于某种原因,以下行在我的 ASP.NET MVC 项目中没有执行任何操作:
System.Diagnostics.Debug.Assert(false);
我已经三次检查我正在使用调试配置,并且在调试配置设置中选中了“定义调试常量”。
我的单元测试项目中也出现了同样的问题。
实现我自己的断言方法看起来很简单,但有点尴尬。任何有关如何解决此问题的提示将不胜感激。
编辑:我在我的项目中使用了多个第三方模块。这可能是由于引用在发布模式下编译的模块引起的吗?
For some reason, the following line does nothing in my ASP.NET MVC project:
System.Diagnostics.Debug.Assert(false);
I have triple-checked that I am using the Debug configuration and "Define Debug constant" is checked in the Debug configuration settings.
The same problem also occurs in my unit test project.
Implementing my own assert method seems trivial, but a bit awkward. Any hints on how to fix this would be greatly appreciated.
Edit: I am using several third-party modules in my project. Could this perhaps be caused by referencing a module which is compiled in release mode?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ASP.Net 断言显示在 VS 控制台中,而您的网页则通过 VisualStudio 显示。它不会像编程语言那样中断线程以显示 MsgBox 或中断断言行。
ASP.Net Assertion are displayed in the VS Console while your webpage is displayed through VisualStudio. It doesn't interrupt the thread to display a MsgBox or break to the assertion line like a programming language.
这是一个古老的问题,但如果您没有定义默认侦听器,它将不会像往常一样显示消息对话框。我还没有确认它是否真的会着火并被吃掉(我怀疑是这种情况)或者它是否根本不着火。
但无论哪种方式,它都不会显示对话框。
来自 DefaultTraceListener
您可以使用如下代码检查侦听器并获取类型:
如果没有名为“Default”的侦听器,
Debug.Assert
将默默失败。就配置而言,假设名为 Default 的侦听器可用,这
将起作用: 假设名为 Default 的侦听器可用,这
将起作用: 这将在我们明确定义默认值时起作用:
这不会起作用:
如果您没有诊断web.config 中的部分,那么默认值可能会被某些 VS 扩展等删除或覆盖,因此添加此部分应该会使其恢复到预期的行为。
Ancient question but if you don't have a default listener defined it will not display a message dialog as per usual. I haven't confirmed whether it actually fires and just gets eaten (I suspect this is case) or whether it just doesn't fire at all.
But either way it will not show the dialog.
From the docs for DefaultTraceListener
You can check your listeners and get the type by using some code like below:
If you don't have one called "Default",
Debug.Assert
will silently fail.As far as configuration goes, this WILL work assuming a listener named Default is available:
This WILL work assuming a listener named Default is available:
This WILL work as we explictly define our Default:
This WONT work:
If you don't have a diagnostics section in your web.config then the Default might be getting removed or overriden by some VS Extension etc, so adding this section should bring it back to expected behaviour.
由于您正在通过 ASP.NET MVC 运行,您的 web.config 中是否有 debug=false 导致了问题?
Since you are running through ASP.NET MVC, could there be a debug=false in your web.config that is causing the problem?