I was reading an article from Jeffrey Richter' book CLR via C#. And I found a nice paragraph about the NGen.exe
tool.
Many people believe that it might be possible to ship NGen’d files without shipping the files containing the original IL code, thereby keeping their intellectual property a secret. Unfortunately, this is not possible. At run time, the CLR requires access to the assembly’s metadata (for functions such as reflection and serialization); this requires that the assemblies that contain IL and metadata be shipped.
I just wanted to clear few thing.
- Does CLR always loads the assembly when the referencing types are there in the assembly.
- Does it do verification check on it?
- When it comes to compiling the code (JIT compiler), does it look for NGen'd code and load the compiled native CPU instructions from that file, or doesn't load the assembly at all when NGen'd file is already there?
No. The CLR will load the assembly once a method is to be JITTED, and is depended an assembly in order to execute. The JIT will instruct the runtime to load that DLL.
Yes, the binder, which is responsible for loading the dll will verify it as a valid assembly via it's metadata in the CLR header (see section below).
Not sure what you mean by "NGENED file already there", but the native binder will look for the native dll as part of the loading process. This article explains the details of loading the assembly to details:
Default context: