Skip to content

Instantly share code, notes, and snippets.

@tmeckel
Last active February 28, 2018 09:27
Show Gist options
  • Save tmeckel/07d17bab6da64e959d0a18d8c4531eba to your computer and use it in GitHub Desktop.
Save tmeckel/07d17bab6da64e959d0a18d8c4531eba to your computer and use it in GitHub Desktop.
Disable optimizations during debugging for .NET assemblies

How to disable optimizations when debugging referenced code in assemblies.

In a nutshell, you need to:

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

Most of the times this isn't enough, because the .NET environment uses the optimization settings for referenced assemblies, regardless of the ZapDisable settings. So the JIT optimizations has to disabled while debugging for such assemblies.

Essentially is comes down to create

  • an .ini file with the same name as the application’s .exe (but with a .ini extension appended of course!)
  • at the positions from which the assmebly is loaded (watch out for asseblied loaded from the GAC!)

with the following content

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

As stated this file must be placed at the same location as the assembly file is stored. This also is true for files loaded from the GAC! So this INI file must be placed in the GAC for instructing the .NET Runtime not to optimize the assembly.

Technically spoken the .ini file must be located at the Codebase from which the assembly is loaded. While your program executes in the debugger inm Visual Studio you can find out from which codebase the assembly has been loaded from the modules window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment