ILearnable .Net

August 27, 2010

Running two versions of NHibernate side by side

Filed under: Uncategorized — andreakn @ 08:33
Tags: , , ,

In my current project we had used NHibernate/Fluent NHibernate (version 2.1.2.4000) for some custom data access for data which shouldn’t live in the EPiServer DB.

Then suddenly we started to integrate EPiServer Community 3.2 (EPiServer Relate + v1.0.1.0) into our solution and stumbled a bit on the fact that it used a different version of NHibernate (version 1.2.0.4000 to be exact)

on the verge of giving up and rewriting our custom data access to raw ADO.net I stumbled upon the solution: using assemblyBinding to instruct .Net *where* to look for the different versions of the dlls. Here’s a snippet from web.config:

<configuration>
   ...
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Iesi.Collections" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
        <codeBase version="1.0.0.3" href="dlllib\nhibernate1.2\Iesi.Collections.dll" />
        <codeBase version="2.1.2.4000" href="dlllib\nhibernate2.1\Iesi.Collections.dll" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
        <codeBase version="1.2.0.4000" href="dlllib\nhibernate1.2\NHibernate.dll" />
        <codeBase version="2.1.2.4000" href="dlllib\nhibernate2.1\NHibernate.dll" />
      </dependentAssembly>
      ...
     </assemblyBinding>
  </runtime>
</configuration>

So what I did was to have a folder structure like this

– site
– – bin
– – dlllib
– – – nhibernate1.2
– – – – Nhibernate.dll (v1.2.0.4000)
– – – – Iesi.Collections.dll (v1.0.0.3)
– – – nhibernate2.1
– – – – Nhibernate.dll (v2.1.2.4000)
– – – – Iesi.Collections.dll (v2.1.2.4000)

So there it is, no more headscratching when different versions of the same dlls are needed. “codeBase” to the rescue!

Create a free website or blog at WordPress.com.