Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

c# - Variable does not exist in the current context while debugging

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...