Monday, September 04, 2006

CLR Runtime Assembly Loading in .Net

The CLR does not first look in the application's private bin directory.
Before the CLR can load an assembly, it must be able to find it. To do this, the CLR makes use of the Assembly Resolver to find the physical assembly and then pass it to the assembly binding mechanism.  After binding the application can use the types defined in the assembly.

The Assembly Resolver resolves for assemblies from different sources in the following order:

1. The GAC, for a native image of the assembly
2. The GAC, for a non-native image of the assembly
3. CodeBase location, if one was defined
4. AppBase directory, otherwise known as the private bin directory
5. Any sub directories as specified in the probing paths, if defined in the application config file

As you can see, the application's private bin directory is #4 , not #1 location. Assemblies in the GAC are system-wide assemblies and therefore take precedence over everything else (assuming versions and other criteria match.)

No comments: