How to do it: Force application runtime to use a different version of an assembly

How to do it
Table of Contents
Summary

Sometimes when the runtime of an application requests a specific version (process named assembly binding) of a DLL it is required to force the use of another version of that same DLL.

Operations
Redirect assembly binding to a specific version of a DLL via configuration file
How to do it

In the sample presented next, each time the assembly “NHibernate, version 1.2.0.4000” is requested by the runtime, the assembly “NHibernate, version 1.2.1.4000″ will be loaded and used instead without throwing an exception of type:

Could not load file or assembly 'NHibernate, Version=1.2.0.4000, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Excerpt of the “Web.Config” file:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" />
        <bindingRedirect oldVersion="1.2.0.4000" newVersion="1.2.1.4000"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
References

[1] http://msdn.microsoft.com/en-us/library/7wd6ex19.aspx
[2] http://msdn.microsoft.com/en-us/library/efs781xb.aspx