Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issuewith NHibernate, Fluent NHibernate and Iesi.Collection. What would you try next?

I'm extremely new to NHibernate so I apologize if I missing something trivial here. I am currently working through a book titled "NHibernate 3 Beginners Guide" from packtpub. I have mostly been following the directions in the book. When I say mostly I have diverged by using MySQL instead of MSSQL and have been using NuGet rather than downloading the binaries by hand.

I am in Chapter 2 at the moment which is the first real coding chapter. In this chapter I am building a simple WPF application to build my database schema through a button click. I have already built some POCO's for the Product and Category classes specified in the chapter. Through NuGet I have added the following references:

  1. MySQL.Data
  2. NHibernate (as a dependency automatically resolved, Iesi.Collections)
  3. Fluent NHibernate

When I click the button to build my database the following code block is executed:

private const string connString = "string omitted for brevity";

private void btnCreateDatabase_Click(object sender, RoutedEventArgs e)
    {
        Fluently.Configure().Database(MySQLConfiguration.Standard.ConnectionString(connString))
            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ProductMap>())
            .ExposeConfiguration(CreateSchema)
            .BuildConfiguration();
    }

Upon clicking the button I receive the following exception (FileLoadException):

Outer Exception Message: Could not load file or assembly 'Iesi.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Inner Exceptions Message: Could not load file or assembly 'Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Here is the "Fusion Log" if that helps:

=== Pre-bind state information ===
LOG: User = Borealis\Frito
LOG: DisplayName = Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
 (Fully-specified)
LOG: Appbase = file:///C:/Users/Frito/documents/visual studio 2010/Projects/NH3BeginnersGuide/Chapter2/App/Sample.UI/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : NHibernate, Version=3.3.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Frito\documents\visual studio 2010\Projects\NH3BeginnersGuide\Chapter2\App\Sample.UI\bin\Debug\Sample.UI.vshost.exe.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 1.0.1.0 redirected to 4.0.0.0.
LOG: Post-policy reference: Iesi.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
LOG: Attempting download of new URL file:///C:/Users/Frito/documents/visual studio 2010/Projects/NH3BeginnersGuide/Chapter2/App/Sample.UI/bin/Debug/Iesi.Collections.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

I have tried the following and now am at a bit of a loss:

  1. Attempted upgrading Iesi.Collections through NuGet but that fails saying there isn't a version for NHibernate that is compatible.
  2. Downloading the binaries for NHibernate and FluentNhibernate and manually referenced them.
  3. Pulling the source samples from the book and copying over the DLLs in the sample. This gave me a different error that I haven't researched far enough to ask questions yet.

I have two questions:

  1. First, why would the NuGet packages attempt to look for a version 4.* dll when the versions that ship point back to 1.*?
  2. What other things should I try to get working short of getting all the source and building locally? I'm at a bit of a loss and would love some other input.

Thanks in advance!

like image 241
Frito Avatar asked Nov 11 '12 15:11

Frito


2 Answers

Holy poopers this drove me nuts. I found that an app.config was created at some point, presumably as I was messing with something. In the app.config I found the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Iesi.Collections" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Commenting out the Runtime element, rebuilding and running allowed the button above to function properly. I'm not sure what I did to cause this to get generated but I'm glad I found it. Thanks all for your efforts to assist and thanks for the upvote on the question!

like image 82
Frito Avatar answered Oct 04 '22 20:10

Frito


Iesi.Collections 4.0 is a heavily modified version targeting .Net 4.0, for use with a future NHibernate 4.0.

Unfortunately Nuget packages for NHibernate versions up to and including 3.3.1 don't specify an upper bound for the Iesi dependency. With NHibernate 3.3.2 this was changed, to explicitly forbid Iesi version 4 or higher. So if you update to NH 3.3.2 via NuGet, I expect it to resolve the Iesi dependency to a 3.x version.

like image 36
Oskar Berggren Avatar answered Oct 04 '22 19:10

Oskar Berggren