In my previous post I introduced Fluent NHibernate and NHibernate Burrow. If you have been trying the two together, you’ll have noticed that Burrow has been compiled against a lower version (2.0) of NHibernate than Fluent NHibernate has (which uses 2.1).

Trying to use Burrow with the newer version of NHibernate results in the following exception being thrown:

FileLoadException: Could not load file or assembly ‘NHibernate,
Version=2.0.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4′
or one of its dependencies. The located assembly’s manifest definition
does not match the assembly reference. (Exception from HRESULT:
0×80131040)

In order to solve this, you could go out and get the Burrow source code from here and compile your own version against NHibernate 2.1. But that’s a lot of work which should become obsolete when the next version of Burrow (or NHibernate) comes out. Instead, you can use assembly redirection.

In your web.config file, add the following:

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

And that’s all you need. Now, whenever some library (read: Burrow) asks for NHibernate 2.0, it’ll be redirected to NHibernate 2.1.

I hope this post was useful to you.

Erik

If you liked this post, please click on one of the advertisements below. Thanks!


9 Responses to “Making NHibernate Burrow work with NHibernate 2.1”

  1. 1 Robert Graves

    This solution got me most of the way there. I had to add two more binding redirections in my project (The last because I’m using .Net 3.5).

    Here are my additional binding redirections.

    However I still get an error due to what looks like a breaking change in NHibernate 2.1. The signiture for NHibernate.Engine.ISessionFactoryImplementor.GetEntityPersister(System.String, Boolean) is now NHibernate.Engine.ISessionFactoryImplementor.GetEntityPersister(System.String). Here’s the error:

    [MissingMethodException: Method not found: 'NHibernate.Persister.Entity.IEntityPersister NHibernate.Engine.ISessionFactoryImplementor.GetEntityPersister(System.String, Boolean)'.]
    NHibernate.Burrow.Impl.PersistenceUnitRepo.GetPU(Type t) 0
    NHibernate.Burrow.Impl.AbstractConversation.GetSessionManager(Type t) 26
    NHibernate.Burrow.Impl.AbstractConversation.GetSession(Type entityType) 13
    NHibernate.Burrow.BurrowFramework.GetSession(Type entityType) 23
    NHibernate.Burrow.AppBlock.DAOBases.GenericDAO`1.get_Session() 36
    NHibernate.Burrow.AppBlock.DAOBases.GenericDAO`1.CreateCriteria() 20

  2. 2 Luca Del Tongo

    Thanks a lot for your last two posts,
    they are really valuable to keep all things updated :)

  3. 3 Erik Burger

    Hi Robert,

    It seems that your post got a bit garbled. If you drop me a line at eburger at reversealchemy.net I can take a look and maybe help you out. I am using .Net 3.5 myself and the binding I described was all I needed. I’d love to help you figure out the rest.

    Erik

  4. 4 Erik Burger

    My pleasure Luca. It’s projects like Fluent and Burrow that make NHibernate a pleasure to use..imho far more than any other product I’ve seen. So anything I can do to help is my privilege :)

    Erik

  5. 5 Luca Del Tongo

    Hi Erik… today i have tried to apply your suggestion in my current project and i receive the same error Robert encounter…
    so i have solved this problem simply by removing assembly redirection inside web.config and after having compiled only the main nhibernate burrrow project, i simply have referenced the new nhibernate.burrow assembly… to compile nhibernate burrow against the latest nh release as Robert suggested it’s necessary to remove a parameter from GetEntityPersister method…
    basically it works with the old school way :)

  6. 6 Erik Burger

    Hi Luca,

    I am glad you got it working though I am still stumped as to why it does work for me. Of course, the excuse “it works on my machine” totally doesn’t apply ;) so I will look into it some more as soon as my calendar frees up a bit. If I find anything I’ll be sure to update my post.

    Cheers,
    Erik

  7. 7 David Carr

    Hi Erik,

    Just to confirm that there are a few breaking changes; one in the Burrow dll and three in Burrow.AppBlock dll (you may not use the latter).

    In Burrow:

    On line 51 of PersistenceUnitRepo.cs. Just remove the extra ‘false’ parameter on the method. The GetEntityPersister method seems to take only one argument in the 2.1 version of NHibernate.

    In Burrow.AppBlock:

    On line 63 of PaginableCriteria.cs change ‘cloned.Orders.Clear();’ to ‘cloned.ClearOrders();’

    On line 307 of GenericDAO.cs change ‘c.Orders.Clear();’ to ‘c.ClearOrders();’

    There’s also an interface (AbstractCriterion) which has been extended in the new NHibernate to include a GetProjections() method, so you need to add the extra method on EqOrNullExpression, which implements this.

    public override IProjection[] GetProjections()
    {
    return null;
    }

    If you have Visual Studio it’s pretty easy to download the source, change the reference to NHibernate to the newer version and recompile with the four changes.

    I hope this helps someone

    David

  8. 8 Erik Burger

    Hi David,

    Thank you very much for your input! I am positive it will indeed help out some.

    Regards,

    Erik

  9. 9 Kyle Koss

    Just thought I’d mention the problem I had when building Burrow against NHibernate 2.1. It seems that if you have Burrow configured to use more than one database it doesn’t work. I kept getting the ‘NHibernate.MappingException: No persister for: ‘ error, and I couldn’t figure out what I had done wrong. So, I downloaded NHibernate 2.0, and set it up with that, and it worked fine.

Leave a Reply