Search code examples
.netclrgacjitnative-code

Does .Net Framework Class libraries in GAC compile each time to Native Code ? Or will it load directly from Native Image Directory ?


I have been reading the book CLR Via C# and in that by using NGen.exe i learnt that i can compile my assemblies to Native Image. This increases the performance. However the native code is customized to my architecture.

When i opened the Native Image Directory
C:\Windows\assembly\NativeImages_v4.0.30319_64\System\d6591361d8701ff6eb6a9df223c24684

I found Native Images for all inbuilt .net framework class libraries.

So my question is Will this Native Images in memory be used directly when our application references one ?

And also does .net framework installer produce the Native images of these class libraries that take full advantage of CPU architecture.

Thanks in advance !!!


Solution

  • Yes, framework libraries are not jitted. They will be loaded from the native images cache.

    You can verify this yourself by inspecting the loaded assemblies path. Tools like process explorer can be used to view the loaded assemblies for the process.

    For example : In my machine mscorlib happens to be loaded from

    C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\blahblahblah\mscorlib.ni.dll
    

    And also does .net framework installer produce the Native images of these class libraries that take full advantage of CPU architecture.

    Not sure what you mean here. Installer does nothing here. It is the ngen.exe which creates the native images. So, yes, it will produce machine code best for the cpu architecture of the machine.