Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2012 - Variable missing from Locals Window

I have never seen this before and have no idea what it causing it.

When I put a breakpoint at the end of code below, the elapsedSeconds variable is NOT listed in the locals window. If I try to Watch it, the Value = "The name 'elapsedSeconds' does not exist in the current context". How is that possible???

public ActionResult Index()
{
    Stopwatch sw = Stopwatch.StartNew();

    var userID = WebSecurity.GetUserId(User.Identity.Name);

    var model = ModelHelper.GetModel(userID);

    long elapsedSeconds = 0;
    elapsedSeconds = sw.ElapsedMilliseconds;

    return View(model);
}
like image 554
SLoret Avatar asked Jan 25 '13 13:01

SLoret


People also ask

How do I show local variables in Visual Studio?

To open the Locals window, while debugging, select Debug > Windows > Locals, or press Alt+4. This topic applies to Visual Studio on Windows.

How do I display a variable value in immediate window?

To view the variable's value, simply type its name into the immediate window and press Enter. The value, "Hello world" will be displayed beneath the typed line, as in the image above. To access properties of a variable or value, use the member access operator (.) as you would within source code.

How do you display variables in Visual Studio code?

Display a data tipSet a breakpoint in your code, and start debugging by pressing F5 or selecting Debug > Start Debugging. When paused at the breakpoint, hover over any variable in the current scope. A data tip appears, showing the name and current value of the variable.


1 Answers

Select 'Code Optimization' property as "Disabled" in Project property window, in case you want to take a look at the value. It's the compiler optimization process, that renders evaluating that variable unnecessary.

like image 146
Manmohan Singh Avatar answered Oct 27 '22 09:10

Manmohan Singh