简体   繁体   中英

VS Immediate Window - The name does not exist in the current context

I've had this thing that keeps bugging me in some parts of code and I have no idea what's causing it.

I have a block of code where I've set a breakpoint. If I then use my cursor and hover over a variable, I can usually navigate the contents and values of that variable.

Whereas some variables, I can't view the contents, nothing appears.

Also, if I try investigating those I can't through the immediate window, it tells me The name 'temp' does not exist in the current context

I'm really annoyed at just WHY this would be happening, some integers but not others, some class objects but not others of the same type.

Closing Visual Studio and restarting doesn't fix it.

I'm running in Debug with no optimization.

Just looking for some help with this issue so thanks in advance.

Here is an example of the code where it occurs, no special code or delegates. It can also happen in random parts of the program even if there are only a few lines of code.

segs2D = ConvertSegmentsTo3DLines(segs2D);
IList<DSegment2D> segs3D = DSegment2D.Duplicate(segs2D);
TransformSegments(segs3D, transform);
foreach (var seg in segs3D)
    MoveSegmentToSolid(seg, moveNormal, solid, false);

Dictionary<double, Strategy> strategiesDic = new Dictionary<double, Strategy>();

double d1 = (double)(segs3D[0].GetP1Tag() ?? 0);
double d2= (double)(segs3D[0].GetP2Tag() ?? 0);
foreach (DSegment2D seg in segs3D)
{
    d1= (double)(seg.GetP1Tag() ?? d1);
    d2= (double)(seg.GetP2Tag() ?? d2);
    ...Stuff
}

Also, if I try investigating those I can't through the immediate window, it tells me The name 'temp' does not exist in the current context

try to use the full name of the method

for example:

namespace.class.method();

instead of

class.method();

it also seems that the immediate window has a dependency to the current selected file/project.

hope this helps Mathias

I had a similar problem. I thought I was in Debug but there was one more simple (but important) step. Where “Solutions Configurations” is set to “Debug” I had to ALSO click the down arrow next to “Debug” and select “Configuration Manager…” and then in that corresponding popup window “Configuration” was still set to “Release” – I had to change that to “Debug” and click the “Close” button. Rerunning from there allowed me to view all variables while debugging.

Maybe the variables are not yet declared or initialized in the block of code where you have hit the breakpoint (ie execution has not got that far).

For example, both the hover and Immediate Window issues you described would occur with respect to bar in the following block of code when you hit the breakpoint:

public class Whatever
{
    public void DoSomething()
    {
        string foo = "blah"; // Breakpoint hit and execution stopped here.

        // Do something.

        DoSomethingElse();
    }

    public void DoSomethingElse()
    {
        string bar = "yack";

        // Do something else.
    }
}

It turns out the the sheer complexity of the method and the number of indents was causing the issue at the time. I've since simplified and functioned much of the original code and am no longer having this issue. I've also upgrade to VS2012 which may also help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM