Search code examples
c#.netsosngen

How do I force the DotNet Framework to use JIT instead of NGEN?


I am debugging an issue related to having native images of DotNet Framework assemblies loaded in a process, e.g. System.Windows.Forms.ni.dll I want to stop these native images from loading. Anyone got any ideas?

Another scenario this would likely be useful for would be if using SOS or some other WinDbg extension for managed code. These tools work for managed code and so you wouldn't don't want the DotNet Framework dlls being converted to native images by NGEN.

Ref: https://learn.microsoft.com/en-us/dotnet/framework/tools/ngen-exe-native-image-generator

Thanks!


Solution

  • You can disable NGEN images loading by setting COMPLUS_ZapDisable environment variable to 1. With this variable .Net should load original assemblies instead of native images. But it'll slow down everything as .Net will need to JIT all the code from Framework assemblies.

    Check this article: https://blogs.msdn.microsoft.com/sburke/2008/01/29/how-to-disable-optimizations-when-debugging-reference-source/