调试时,当前上下文中不存在变量 [英] Variable does not exist in the current context while debugging

查看:150
本文介绍了调试时,当前上下文中不存在变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我插入了两个临时变量,并希望看到它们的值,但是我不能。我可以把它放在别的地方,但我有兴趣为什么这个行为存在。

  public float Value 
{
get
{
float result = Memory.ReadFloat(Address);

double Radian = Math.Round(result,2); // ** BREAK POINT HERE **
double Degree = Math.Round(Math.Round((double)(result * 180 / Math.PI)),2); // ** BREAK点在这里**

返回结果; // ** BREAK点在这里**
}
}

我打破在所有三点上,但我无法让Visual Studio 2012向我显示这些值。只有结果将显示在本地窗口中,没有称为Radian或Degree的变量。



如果我添加了Radian变量的手表,我会得到这个消息一个红十字图标:


Radian - 当前上下文中不存在Radian名称



解决方案

可以通过JIT编译器优化局部变量。由于您使用Visual Studio,您可能可以将配置切换到Debug并重建。



如果没有,您可以将JIT编译器配置为禁用优化并生成跟踪信息 - 请参阅此处关于如何设置配置。这应该允许您在将调试器附加到进程时看到本地变量。


I inserted two temp variables and want to see their values, but I can't. I could solve it by placing it somewhere else, but I'm interested why this behaviour exists.

   public float Value
    {
        get
        {
            float result = Memory.ReadFloat(Address);

            double Radian = Math.Round(result, 2); // **BREAK POINT HERE**
            double Degree = Math.Round(Math.Round((double)(result * 180 / Math.PI)), 2); // **BREAK POINT HERE**

            return result; // **BREAK POINT HERE**
        }
    }

I break on all three points, but I can't get Visual Studio 2012 to show me the values. Only result will show up on the locals window, there is no variable called Radian or Degree.

If I add a watch for Radian variable for example, I get this message with a red cross icon:

Radian - The name 'Radian' does not exist in the current context

解决方案

It's possible the local variables have been optimised away by the JIT compiler. Since you're using Visual Studio you might be able to switch the configuration to Debug and rebuild.

If not, you can configure the JIT compiler to disable optimisations and generate tracking information - see here on how to set the configuration. This should allow you to see local variable when you attach the debugger to the process.

这篇关于调试时,当前上下文中不存在变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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