我可以阻止CLR优化调试信息吗? [英] Can I prevent the CLR from optimizing away debugging information?

查看:78
本文介绍了我可以阻止CLR优化调试信息吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为单元测试编写了一个抽象基类,它为我们的测试设置了恰好足以运行的环境.该类将某些运行时环境位公开为属性,这些属性的类型根据测试的不同而有所变化(这些属性类型是在继承的具体测试类中指定的类型参数).

I've written an abstract base class for unit tests that sets up just enough environment for our tests to run. The class exposes some of the runtime environment bits as properties whose types vary test by test (the property types are type arguments specified in the inheriting, concrete test class).

一切都很好,除了一个同事注意到他无法在调试器中查看类的任何属性之外.事实证明,原因是他在继承类中没有定义任何字段,并且CLR优化了某些内容或其他内容,因此调试器无法显示属性.是否有可能以某种方式在基类中防止这种情况发生,还是我不得不诉诸于每个人,他们需要定义至少一个在测试期间某处使用的字段?

This is all well and good, except a co-worker noticed that he can't view any of the class' properties in the debugger. Turns out the reason is that he had no fields defined in his inheriting class, and the CLR optimized something or other away, so the debugger couldn't display the properties. Is it possible to prevent this in the base class somehow, or do I have to resort to telling everyone they need to define at least one field which is used somewhere during the tests?

优化/调试设置应该听起来像是罪魁祸首.就是说,我是从Visual Studio的Debug模式构建应用程序的,我已经仔细检查了所有项目都已设置为调试版本,并且此解决方案中的所有项目都未设置Optimize标志.

Sounds like a likely culprit should be the optimization/debug settings. That said, I'm building the app from Visual Studio in Debug mode, I've double-checked that all projects are set for a debug build, and none of the projects in this solution have the Optimize flag set.

也许还需要注意的是,我正在使用MSTest和Visual Studio测试运行程序.

Perhaps it would also be relevant to note that I'm using MSTest and the Visual Studio test runner.

当我在Quickwatch中评估属性并获得红色感叹号和文本无法评估表达式"错误文本时,是指无法查看属性".唯恐您以为我完全怀疑我,添加一个在测试initialize方法中初始化过的实例字段会使问题消失……

By "can't view properties" I'm referring to when I evaluate the property in Quickwatch and get a red exclamation mark and a text "Could not evaluate expression" error text. And lest you think I'm entirely off base with my suspicions, adding an instance field that gets initialized in the test initialize method makes the problem go away...

检查了构建输出.我注意到编译器是通过以下选项调用的:

Checked the build output. I notice that the compiler is invoked with these options:

/debug+
/debug:full
/optimize-
/define:DEBUG,TRACE

我应该认为这足以阻止这种情况的发生,但是您就可以了. :)

I should think that would be enough to stop this from happening, but there you go. :)

推荐答案

我之前也遇到过同样的问题,这总是由于调试模式已通过某种方式关闭而引起的.尝试检查以下各项:

I've encountered this same problem before, and it's invariably due to the fact that Debug mode has been turned off in some way. Try checking each of the following:

  1. 该解决方案和适当项目的当前构建配置为 Debug .
  2. 在属性页的 Build 标签中,优化代码复选框是未选中.
  1. The current build configuration for the solution and the appropiate project(s) is Debug.
  2. In the Build tab of the property pages, the Optimize code checkbox is unchecked.

如果这都是正确的,那么我建议您在此处粘贴写入 Output 窗口的文本,这样我们就可以潜在地发现问题的任何其他异常原因.

If this is all correct, then I recommend you paste the text written to the Output window here so can we can potentially spot any more unusual cause of the issue.

这篇关于我可以阻止CLR优化调试信息吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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