Visual Studio 启用断言
我试图将断言语句添加到项目中,但它们一直被跳过。 我需要在某处启用一个选项吗?
断言语句是:
Debug.Assert(false, "Deserialization failed", "Deserialization failed");
并且我正在调试模式下运行。 我可能正在做一些愚蠢的事情; 我不知道。
I am trying to add assert statements to a project, but they keep being skipped. Is there an option I need to enable somewhere?
The assert statement is:
Debug.Assert(false, "Deserialization failed", "Deserialization failed");
And I am running in debug mode. I could be doing something silly; I am not sure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保定义了 DEBUG 条件编译符号。 在 VS2008 中,位于“构建”选项卡上的项目属性页上:“定义 DEBUG 常量”。 对于调试版本来说,默认情况下应该是这种情况,但它可能已被关闭。
在其他 IDE 中可以以类似但不同的方式设置/取消设置(可能使用编辑控件而不是复选框)。
也有可能(但不太可能)它被配置文件设置禁用,或者使用
设置,或者因为 DefaultTraceListener 已从听众收藏。 如果您认为这可能是发生的情况,请参阅 Debug.Assert() 方法的文档以获取更多详细信息。Make sure the DEBUG conditional compilation symbol is defined. In VS2008 that's on the project's property page on the Build tab: "Define DEBUG constant". This should be the case by default for a debug build, but it's possible that it got switched off.
It may be set/unset in similar but different ways in other IDEs (possibly with an edit control instead of a checkbox).
It's also possible (but rather unlikely) that it is being disabled by a configuration file setting, either with an
<assert assertuienabled="false" />
setting or because the DefaultTraceListener has been removed from the Listeners collection. See the documentation for the Debug.Assert() method for more details if you think this might be what's going on.