无法获得价值,因为它已经过优化 [英] Cannot obtain value because it has been optimized away

查看:116
本文介绍了无法获得价值,因为它已经过优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在调试时遇到问题...
突然间,我在调试时看不到大多数变量的值。
我已经设法在即时窗口中得到了两种不同的消息:


无法获取局部值或参数'parameter'的值



,因为它在该指令指针处不可用。


表达式计算器中的内部错误。


我已经尝试并检查了以下内容:


  1. 解决方案配置设置为调试(版本)

  2. 项目->设置->构建->优化代码未设置

  3. 工具->选项->调试->使用Managaed兼容模式(没用)

您还有其他想法可以重新进行调试吗? :(



预先感谢



编辑
代码为没有什么特别的..当我尝试观察参数[Key]

中的内容时发生。

  public void AddOrUpdateQuartzJob(string jobName,IList< KeyValuePair< string,string>>参数)
{
var jobDetail = this.GetJobDetail(jobName);

if(jobDetail!= null)
{
foreach(参数中的var参数)
{
jobDetail.JobDataMap [parameter.Key] = parameter.Value;
}
}
else
{
this.ScheduleNewJob(jobName,parameters);
}
}


解决方案

我找到



没有优化:




I have a problem with debugging... All of a sudden I can't see the values of most variables while debugging. I've managed to get two different messages in the Immediate Window:

Cannot obtain value of local or argument 'parameter' as it is not available at this instruction pointer, possibly because it has been optimized away.

and

Internal error in the expression evaluator.

I've tried and checked the following things:

  1. Solution Configuration is set to debug (not release)
  2. Project -> Settings -> Build -> Optimize code is not set
  3. Tools -> Options -> Debugging -> Use Managaed Compatibility Mode (didn't work)

Do you have any further ideas how I can properly debug again? :(

Thanks in advance

Edit The code is nothing special.. it happens when I try to watch what's inside parameter[Key]

public void AddOrUpdateQuartzJob(string jobName, IList<KeyValuePair<string, string>> parameters)
    {
        var jobDetail = this.GetJobDetail(jobName);

        if (jobDetail != null)
        {
            foreach (var parameter in parameters)
            {
                jobDetail.JobDataMap[parameter.Key] = parameter.Value;
            }
        }
        else
        {
            this.ScheduleNewJob(jobName, parameters);
        }
    }

解决方案

The best way I've found to convince the JIT compiler not to optimize the code is to use an INI file with the name of the assembly in the same folder the assembly is in with the contents:

[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0

Note that it has to be the name of the assembly, not the name of the process EXE (unless it is the EXE assembly you want to debug). E.g. if you have an assembly MyCode.dll the INI file name would be MyCode.ini.

Here are some slides from a presentation on .Net debugging which show the difference:

With Optimization:

Without Optimization:

这篇关于无法获得价值,因为它已经过优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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