6

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);
}
SLoret
  • 1,531
  • 3
  • 18
  • 31
  • 3
    Has it been optimised away in a Release build, because it has no effect? – RichieHindle Jan 25 '13 at 13:38
  • Holy Crap.... to my defense it is early in the morning and I haven't had my coffee. Thank you @RichieHindle. For anyone who stumbles across this... I just needed to switch my build configuration back to debug... duh. – SLoret Jan 25 '13 at 13:45

3 Answers3

7

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.

Manmohan Singh
  • 439
  • 1
  • 3
  • 15
  • 1
    It is good to disable optimizations in Debug Configuration. In case of Release Configuration by default it is "Maximize Speed" – Vinod T. Patil Apr 13 '15 at 11:08
0

I got this too in a Web project. Neither restarting Visual Studio or any other solution in this thread sovled it.

My solution was to restart IIS. After that I rebuilt the project and started it and got locals to work again.

Robert
  • 2,357
  • 4
  • 25
  • 46
0

Rebuilding the solution helped in getting the variable hover feature back.