0

I have a project which uses NHibernate.dll. We moved the project to use .Net Framework 4.0. We use FxCop and FxCop start failing and error appeared

Could not resolve assembly Nhibernate.dll so my guess was if i could move NHibernate.dll to move to .Net Framework 4.0 that would do the trick.

I tried and it gave like 100 errors about which ISet am i using is it System.** or Ies.Collections.Generic. I used Ies.Collection.Generic because Nhibernate has a reference to it.

I successfully managed to migrate it to .Net 4. but when I accessed my web application I got below message.

Inheritance security rules violated while overriding member: 'NHibernate.Cfg.Configuration.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

Although I am not overriding anything at all. I searched on internet and found couple of article but I do not want to change NHibernate code Because that is not my code.

Why am I not using latest NHibernate? because when I used this my project broke and the error was there is no overload method which uses 3 parameters (which my project uses) for

FilterDefinition(string name, string defaultCondition, IDictionary<string, IType> parameterTypes, bool useManyToOne);

Now they have 4th parameter which I am unsure what the results will be.

Question:

Could someone please help me with this error?

Has someone migrated NHibernate to .Net 4 successfully?

thanks

References:

http://forums.lhotka.net/forums/t/9914.aspx

Inheritance security rules violated while overriding member - SecurityRuleSet.Level2 http://community.codesmithtools.com/Template_Frameworks/f/67/p/12331/47618.aspx#47618

Weird override problem with Fluent NHibernate and .NET 4

Community
  • 1
  • 1
Kamran Pervaiz
  • 1,861
  • 4
  • 22
  • 42
  • 1
    Why do you need to migrate it to .NET 4? It will run as is on a .NET 4 project. – eulerfx Sep 21 '12 at 16:36
  • 1
    Regarding the violated security rules, these seem to be the changes that was necessary to get NHibernate 3.3 to build for .Net 4: https://github.com/oskarb/nhibernate-core/commit/d5f10c538440c127341159b31bff242ff9d687af Note though that build NH on .Net 4 should not be necessary. Also, work is currently in progress on NH4 which will target .Net 4. – Oskar Berggren Sep 22 '12 at 16:49

2 Answers2

1

I know this is not quite the answer you are looking for, but this is how I approached upgrading from:

asp.net 2.0, IIS6, NH 2.1, MVC2 project to:

asp.net 4.0, IIS7.5, NH3.3, MVC4

  1. Make sure I have integration tests across most of the project (I won't lie this is what took a lot of my own time to achieve). Also use an error logging module like ELMAH
  2. Upgrade to NH 3.3, run tests, push live and leave for a week to catch any bugs.issues
  3. Upgrade to SLN .NET 4 (NO RECOMPLING OF NH IS NEEDED), run tests, push live and leave for a week to catch any bugs
  4. Upgrade from MVC2 to MVC3, run tests and push live, leave for a week
  5. Finally updgrade from MVC3 to MVC4

Personally I found this was the best approach and certainly gave me less pain points as I did not do too much at any one time. Also I could not have done this without integration tests covering probably around 70% of my code.

If I had gone straight to .net 4 and NH.3.3 then I would have been in a world of pain as there are always issues upgrading any project. My advice for what is is worth is to do it slowly.

Also the great think about having integration tests that an future code modifications or upgrades should be painless.

Rippo
  • 22,117
  • 14
  • 78
  • 117
1

This below link helped me which oskar commented

https://github.com/oskarb/nhibernate-core/commit/d5f10c538440c127341159b31bff242ff9d687af

Kamran Pervaiz
  • 1,861
  • 4
  • 22
  • 42