How to disable optimizations during debugging

How to disable optimizations during debugging

  • Comments 2

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!

  • 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.

  • 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.

Page 1 of 1 (2 items)
Leave a Comment
  • Please add 2 and 7 and type the answer here:
  • Post