Search code examples
.netasp.netnhibernateassembliesassembly-resolution

How to resolve conflicting assemblies in .Net?


In my web application I am using NHibernate.dll. This has a dependency on folowing assembly.

'Antlr3.Runtime, Version=3.1.0.39271, Culture=neutral, PublicKeyToken=3a9cab8f8d22bfb7'

Now in the same project for another requirement I have to introduce Antlr3.StringTemplate.dll. Which has a dependency on another version of the above assembly.

If I use the version of Antlr3.Runtime.dll which satisfies NHibernate , Antlr3.StringTemplate starts complaining and vice-versa.

How to resolve a situation like this?


Solution

  • You could probably use assemblyBinding in your web.config to redirect your newest version to the old version.

    Example:

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

    This goes directly under the <configuration> node in your web.config.

    You can read bout it here: http://msdn.microsoft.com/en-us/library/2fc472t2%28VS.71%29.aspx