How to disable optimizations during debugging

Sooner or later you may run into a situation where you need to evaluate a local variable under debugger and all you get is this:

"Cannot obtain value of local or argument 'whatever' as it is not available at this instruction pointer, possibly because it has been optimized away'.

Well, it turns out there are two different tricks to solve such problems:

1.

Shawn Burke blogs about How to disable optimizations when debugging Reference Source. In a nutshell, you need to:

  1. Start VS with the Environment Variable COMPLUS_ZapDisable=1
  2. Disable the VS Hosting Process (.vshost.exe) before you start debugging

2.

Another tip is from our VB IDE Dev Jared Parsons: Disabling JIT optimizations while debugging. Essentially, Jared points to create an .ini file with the same name as the application's .exe:

[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0

He also points to the MSDN article http://msdn.microsoft.com/en-us/library/9dd8z24x.aspx (Making an Image Easier to Debug).

To be frank, this tip didn't work for me for some reason, but I guess it's still worth mentioning.

Hope this helps!