Strong naming is used together with a "public key token" to produce an assembly full display name (mscorlib, version=2.0.0.0, Culture=neutral, PublicKeyToken=b4778,.....
). This enables us have multiple versions of the same assembly side-by-side within the same application directory.
A public key token (and hence, string naming technique) also allows the .NET loader to detect whether anybody has tampered with your assembly contents since you distributed it. This is true because when you sign an assembly with your "private token", the compiler will generate a hash value which it embeds into the assembly metadata that describes the public portion of your "private token". The loader can then use this value to determine whether or not your assembly was modified.
Concerning resolving assemblies, there are a few basic things to consider:
Probing
The loader attempts to locate assemblies using a basic directory "probing" technique. This means that it will try to locate "MyAssembly.dll
" (for instance) in the application's startup directory, if not there, then in subdirectories below that. If probing fails to locate "MyAssembly.dll
", then the AppDomain
's AssemblyResolve
event is fired.
Machine/User/System configuration
The machine.config
, user.config
and system.config
are configuration files stored locally on the system which one can use to change the behavior of the assembly resolver on a "machine", "user" or "system"-wide setting.
Publisher Policy
One can use the "<assemblyIdentity>
" XML token in your application's configuration file (for instance, "MyApp.exe.config
") to point to resolver to a certain version of an assembly or to load an assembly from a different location.
Custom resolution
Handle the "AssemblyResolve
" event of the AppDomain
. This event is raised whenever an assembly could not be resolved via "traditional" methods
By far the least complicated mechanism is to handle the "AssemblyResolve" event.
To summarize, the resolver looks in the current directory or the Global assembly cache, processes policy and then finally allows custom resolution.