Contract Sitecore developer and technical consultant based in London. Mainly working with ASP.net and Sitecore CMS.

Numerous times in recent years I’ve had to use Reflector Pro to debug third-party dlls. While this works well and allows you to step through code as if it was your own the value of doing so can be completely lost if you cannot see critical object values due them being ‘optimized away’.

Recently I was stuck with a problem of optimization that refused to be disabled by the usual means that I’d used in the past. I stumbled onto a neat trick which finally did work, but it also clarified what happens when the web application, usually Sitecore CMS, restarts.

Is it even optimized?

We’d better check, else we could be chasing rainbows. With the debugger attached, you can open the ‘modules’ window (Debug > Windows > Modules) and see the status of the dlls loaded. Sure enough this confirmed that the code being looked at was indeed still optimized despite using both of the standard fixes described here.

Disable Optimizations

The usual settings to turn off optimization are to either A) Launch Visual Studio with the environment variable ‘COMPLUS_ZapDisable=1‘ set, or B) Drop an .ini file alongside the dll in use. Both are described in great detail in relation to Sitecore on this JammyKam blog post so I won’t duplicate further here. In any case, the problem was that for some reason neither technique was working, and not for the first time. Hiding in the comments of that same post was a killer tip from Chris van de Steeg – first attach the debugger, and then save a change to web.config to invoke a restart. Sure enough, this works!

An app domain restart will reload modules and re-JIT optimize them but the presence of the attached debugger successfully prevents JIT optimizations from occurring. Now I can step through third-party code with Reflector Pro and with full visibility of locals and autos.

Kudos to Jammykam and Chris for sharing. It’s made using Reflector Pro for debugging something that I can rely upon again.

Post navigation

Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Authenticate this comment using OpenID.

Notify me of follow-up comments by email.

Notify me of new posts by email.

Search for:

Disclaimer

All data and information provided on this site is for informational purposes only. Paulgeorge.co.uk makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this site and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis.