I’m trying to debug some code in the .NET Framework. Unfortunately, many of the variables are optimized away, and I can’t reliably set the instruction pointer due to flow optimizations.
Is it possible to force the runtime to NOT use the ngen’d versions of the .NET system DLL’s, but instead use the MSIL, forcing optimization to ‘off’?
Note: I’ve tried using the INI trick to set AllowOptimize=false but it made no difference.
Got the answer from John Robbins. Basically, stick COMPLUS_ZapDisable=1 in your env vars (wrap in a bat to avoid running the whole system unoptimized) and disable the VS hosting process.
http://blogs.msdn.com/sburke/archive/2008/01/29/how-to-disable-optimizations-when-debugging-reference-source.aspx
Another option is the new .NET Reflector Pro that lets you selectively decompile/recompile assemblies unoptimized. Not necessary with reference source but a good backup.
http://www.red-gate.com/products/reflector/features_pro.htm