views:

51

answers:

3
  1. Is it loaded when a class from the assembly referenced?
    Or
  2. When a class which declares the using namespace from the Assembly is loaded?

Also having loaded an assembly does it ever unloads the assembly if it is not used for a long time?

A: 

Assemblies are loaded in various ways (Project references, direct references--both of these during compile-time (OK, apparently not)), but not by Using statements. They are to my knowledge never unloaded again.

Sheeo
+4  A: 

It's the JIT compiler that instructs the CLR to load an assembly once it has translated it to machine code which is done on demand and the exact time is not deterministic. As to the second question, once an assembly is loaded into the AppDomain, the only way to unload it is to destroy this AppDomain, there's no other way to unload an assembly.

Darin Dimitrov
+1, accurate except for "once it has translated". The translate chicken is after the load egg.
Hans Passant
A: 

It is loaded when you attempt to use a type from the assembly. When the program gets to executing a type that it doesn't know about it, the runtime goes and resolves the type, which then loads the assembly that contains that type.

Darren Kopp