Install NHibernate 3.2 with NuGet - nhibernate

I'm new to NHibernate and have been trying to get up and running with it, Fluent NHibernate and NHProf using NuGet. After reading this article (http://gurustop.net/blog/2011/03/13/nhibernate-3-1-0-on-nuget-important-details) it seems that v3.1 shouldn't be directly installed, however, there appears no such warning for v3.2.
After successfully installing NHibernate 3.2 and NHProf using NuGet, I'm unable to install Fluent NHibernate as it says it's "Already referencing a newer version of NHibernate".
Also, when I run my app I get the following error "Could not load file or assembly 'NHibernate.ByteCode.Castle' or one of its dependencies". The following link (Could not load file or assembly in NHibernate) suggests installing a number of additional assemblies, which is what I was hoping to avoid by using NuGet in the first place.
At this point would it just be easier to follow the steps on NHForge to get things up and running as the packages on NuGet don't appear to be compatible?

NHibernate 3.2 comes with its own proxy factory. If you're using a config file, you just need to remove the proxyfactory configuration property.
I believe the version of Fluent NHibernate that you're using defaults to use NHibernate.ByteCode.Castle. In that case, you would need to override that setting with the built in NHibernate 3.2 proxy factory:
.ProxyFactoryFactory("NHibernate.Bytecode.DefaultProxyFactoryFactory, NHibernate")

Each version of Fluent NHibernate uses an exact version of NHibernate (included in the Fluent NHibernate package)
You should remove the NHibernate package and add only Fluent NHibernate

If you use the Nuget Package Manager Console instead of the GUI to get the package (Install-Package FluentNHibernate) you will get version 1.3.0.717 which is compatible with NHibernate 3.2
I tried and is working fine for me. I answered this already on this link: which version of fluent nhibernate is compatible with nhibernate 3.2

I'm using this consctruction in config file to make FluentNhibernate work with NHibernate 3.2
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.2.0.1001" newVersion="3.2.0.1001" />
</dependentAssembly>
</assemblyBinding>
</runtime>

NHibernate 3.2 comes with its own mapping configuration (Conform). FluentNHibernate only works with NHibernate 3.1 as a result of this, you can't use 3.2 (I had the same problem). So you'll have to manually download 3.1 and reference that unless NuGet allows you to use 3.1 directly.
Your other option is to remove all references to 3.2 and then install FluentNHibernate from NuGet, then the dependency resolver will kick in and automatically include NHibernate 3.1 for you.

Related

Upgrade to NHibernate 3.2

I have a project by NHibernate (version 2.1). For upgrade to NHibernate 3.2, what should I do?
Do I need that upgrade following dll?
Antlr3.Runtime
Castle.Core
Castle.DynamicProxy2
NHibernate.ByteCode.Castle
I could not find those dll in NHibernate 3.2. Now what should I do?
They are not needed any more. Just delete all dlls that are not there any more (except maybe log4net, that's now optional but without it there won't be any logging).
You might also get errors in your hibernate.cfg.xml, just remove the deleted elements like ProxyFactoryFactory.

upgrade to nhibernate 3.1

I have a project using NHibernate (version 2.2). For upgrade to NHibernate 3.2 , What should I do?
Do I need that upgrade following dlls?
NHibernate.Linq.dll
Iesi.Collections.dll
Castle.Core.dll
Castle.DynamicProxy2.dll
Log4net.dll
Do I need that upgrade hbm files? Do I need that upgrade hibernate.cfg.xml file?
When upgrading to NH 3.2 you don't need NHibernate.Linq.dll anymore, but method name that is used to get LINQ support is not Linq<T> - its Query<T> now
You don't need to change hbm files
You will need to update Iesi.Collections assembly
You don't need castle.dynamic proxy dll (you still can use it, but its not required anymore)
Log4Net is not required anymore
You will probably need to change your cfg file in order to change dynamic proxy settings
The easiest way to get latest version of NH with all required assemblies is to use Nuget
upgrade the dlls and test your program, normally this should be enough

which version of fluent nhibernate is compatible with nhibernate 3.2

i see when i install fluent nhibernate 1.2 from Nuget, it downloads nhibernate 3.1. If i want to use nhibernate 3.2, how would i do that through nuget and it is compatible with fluent nhibernate 1.2 ?
If you use the Nuget Package Manager Console instead of the GUI to get the package (Install-Package FluentNHibernate) you will get version 1.3.0.717 which is compatible with NHibernate 3.2
I tried it and is working fine for me.
Here you can read about plans to release FluentNHibernate for 3.2GA soon and a suggested workaround using attributes
http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/8e782e45ed9ba647
I got my working using
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NHibernate"
publicKeyToken="aa95f207798dfdb4"
culture="neutral" />
<bindingRedirect oldVersion="3.1.0.4000"
newVersion="3.2.0.4000"/>
</dependentAssembly>
</assemblyBinding>
Currently, the FluentNHibernate package from the offical NuGet package source, depends on NHibernate.Castle 3.1 (currently, there is no newer version yet), which in turn depends on NHibernate 3.1 (the exact version, not 3.1 or higher). Therefore, NuGet infers a dependency on NHibernate 3.1 when installing FluentNHibernate.
So the bottom line is: you can't, until the FluentNHibernate package is updated.
The most practical way around is getting the latest FluentNHibernate source code and building it against NHibernate 3.2. I've tested that and it seems to work just fine. You might even be fine using assembly binding redirects, but I haven't tested that.
Alternatively, you can wait for NHibernate 3.2 to reach GA (final) and FluentNHibernate to catch up, but of course that's not a very satisfying answer.

upgrading NHibernate and NHibernate Validator w/ Nuget

As of the today, the Nuget release of NHibernate Validator is 1.3.1.4000 and says it has a dependency >= NHibernate 3.1.0.4000, which implies it should work with latest NHib 3.2.
But NHib 3.2 now has its own ProxyFactory, so running the two gets the following error:
System.TypeLoadException : Could not load type 'NHibernate.Bytecode.ProxyFactoryFactoryNotConfiguredException' from assembly 'NHibernate, Version=3.2.0.2001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4'
I do not really need anything in NHib 3.2 now, although my preference would be to make the two work together.
Alternatively, I suppose I could drop down to NHib 3.1, but my solution has 16 projects, which where Nuget comes in. This post suggests how to get and install an older package release, but NHib 3.1 doesn't seem to be available stand alone from Nuget.
Installing Validator alone using Nuget will install the NHib 3.1 as a dependency. I have some projects that don't use Validator but do use NHib alone, and I guess I could install Validator just to get the correct dependency but that isn't a very satisfying solution.
Has anyone got the latest NHib (3.2) working with the latest NHib Validator? Suggestions?
Cheers,
Berryl
If you feel OK about using NHib 3.1 you can first add the Validator + its dependency on NHib 3.1 to the projects that require validation. Afterwards, referencing the NHib package in other projects can be done at the solution level (introduced in NuGet 1.4)

Fluent NHibernate 1.1 and castle.core 2.5.0.x together issue

I'm using the latest stable build of Fluent NHibernate ver 1.1. Now in the application I'm also using castle.core for dependency injection. Now the problem is using them together. In Visual Studio castle.core says ver. 2.5.1.0 but in Windows Explorer "details" for the same DLL file it says 2.5.1.2121. I have tried both numbers in assembly binding in the web.config, to switch away from ver. 1.1.0.0 which the Fluent NHibernate castle.core references, but not with much luck.
Any suggestions to solve this issue? I do not want to build any of the assemblies myself.
The only solution I came across with this was to get the nhibernate.bytecode.castle source and build it against the latest source for castle.core - alternatively you could use a nhibernate.bytecode.linfu instead.
I rebuilt Fluent NHibernate against the latest Castle Project core and Fluent NHibernate beta2. Now it works.
I just found the solution. I used the MVC contrib project and this was the source to the problem, the Windsor controller factory. I wrote my own and removed the reference, only a few lines of code, problem solved.