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

How to do it
Table of Contents

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.

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” is requested by the runtime, the assembly “NHibernate, version″ will be loaded and used instead without throwing an exception of type:

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

Excerpt of the “Web.Config” file:

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