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:


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


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]

He also points to the MSDN article (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!

Comments (4)
  1. Mike says:

    The second suggestion worked for me. I was debugging a WCF service hosted as a windows service. Attaching to the process was causing the same error. I uninstalled the service in question. Created a new {myProjectName}.ini with the text editor of your choice with the above section and settings in the same folder as the exe which was installed. From there attaching to the process and breaking in no longer throws the "Cannot obtain value…" error.

  2. Ethan Woo says:

    Attaching to the process always shows the error for IIS hosting WebApp,  after i debug with F5 for the Hosted WebApp, local variable can be evaluated.

  3. Ab says:

    Second one worked for me. Thank you.

  4. Rory says:

    For the INI, you need to make a separate .ini for each assembly you want to disable optimizations for. E.g. If you want to debug MyAssembly.dll in the EXE, make a MyAssembly.ini file.

Comments are closed.

Skip to main content