Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLR dependent assembly resolution at startup

Tags:

.net

clr

Does CLR try to resolve [not necessarily load] all the dependent assemblies when the program starts up? That is, is the dependent assembly resolution done on demand? Please note that I am not talking about Assembly.Load* [reflective] kind of load.

like image 440
Fakrudeen Avatar asked Dec 29 '22 03:12

Fakrudeen


1 Answers

It is the JIT compiler that directs the loading of assemblies, in response to translating IL to machine code. Type method calls are at first translated to call a stub function. When called, this stub activates the JIT compiler to load the IL (which loads the assembly if necessary) and translate it. Very much on-demand.

One wrinkle in this process are assemblies that were run through Ngen.exe, all the .NET framework assemblies were when they were installed on the machine. This is detected when an assembly is first loaded. The JIT compiler then skips the translation step and uses the pre-translated machine code as-is. While this will load all of the machine code produced by an assembly, it is still on-demand. The term "load" is relative here, Windows uses a memory mapped file to map the native image into the virtual memory space. No actual bytes are read from the file until code execution arrives at a memory page that hasn't been mapped into RAM yet. The technical term for this is "page fault", it is visible in Taskmgr.exe.

like image 110
Hans Passant Avatar answered Jan 15 '23 11:01

Hans Passant