How to do it: Specify where the common language runtime can find an assembly

How to do it
Table of Contents
Summary

Sometimes the location of an assembly must be explicilty indicated to the runtime.

An elegible scenario would be if two different assemblies requires different versions of the same assembly to coexist in the application runtime: In this case two distinct directories must be configured otherwise at compile time the assemblies will override each other in the target compilation directory

Note

If the assembly has a strong name, the codebase attribute can be anywhere on the local intranet or the Internet.

If the assembly is a private assembly, the codebase attribute must be a path relative to the application’s directory.

Operations
Specify where the runtime can find a specific assembly via configuration file
How to do it

In the sample presented next:

  • each time the some class/method of the assembly “log4net, version 1.2.0.10is invoked, then  the runtime will locate the assembly on directory “bin\lib\log4net_1.2.10″ and will load it;
  • each time the some class/method of the assembly “log4net, version 1.2.0.11is invoked, then  the runtime will locate the assembly on directory “bin\lib\log4net_1.2.11″ and will load it;
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <!--log4net bindings for nhibernate -->
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" />
        <codeBase version="1.2.10.0" href="bin\Lib\log4net_1.2.10\log4net.dll" />
      </dependentAssembly>
      <!--log4net bindings for umbraco -->
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" />
        <codeBase version="1.2.11.0" href="bin\Lib\log4net_1.2.11\snk\log4net.dll" />
      </dependentAssembly>
  </runtime>
</configuration>