NHibernate and trust mode

I have just uploaded my application to my hosting provider and got the following error.

“System.Security.SecurityException: That assembly does not allow partially trusted callers.”

After investigation it appears the problem lies with NHibernate and that it will only work in “Full Trust” mode. I have registered this with support who report that it’s a NHiberate problem and there’s nothing they can do until NH fix it.

Has anybody else experienced this problem and gotten around it?

btw: my hosting provider only allow medium trust

Hi tdk68304,

Thank you for your post. I am sorry that “full trust” is necessary for running NHibernate, and also our ORM layer.

Best regards,
Jick

Have you tried this?

http://forum.hibernate.org/viewtopic.php?t=971532

Hello tdk68304,

I notice that you have been requesting for the source to perform the customization yourself. Have you received our message with the source? Did you try and was it success?

Best regards,
Jick

I added the [assembly: System.Security.AllowPartiallyTrustedCallers] in the AssemblyInfo file but this didn’t work.

I think NH v1.2 fixes several issues. Will you be upgrading your code base?

Would it be worth seperating your ORM code from the NH code that way users could apply HN updates (providing there’s nothing radically different in the NH code) without being dependent on you guys for updates?

Hello tdk68304,

Sorry for keep you waiting. We may upgrade to version 1.2 when its stable release is ready. About separating ORM, we recommend you to generate as POJO and then use pure NHibernate.

Best regards,
Jick

Hi,

I also had the problem making NHibernate work with medium trust and this is what I did:

First…you need some sort of hosting that allows reflection in your server…There are some like crystaltech.com which will allow you to use reflection (in shared hosting) as long as it is used for assemblies within your designated app folder.

Second…

Download the Castle.DynamicProxy-vs2005 project. NHibernate ships with the dll, but you will need to modify the assembly to allow lazy loading under medium trust. Once you have the assembly, make sure nhibernate references this assembly and not the old dll.

Open the Castle.DynamicProxy-vs2005 project and look for the ModuleScope.cs file (it is right in the main directory). There look for the method:
private AssemblyName GetAssemblyName (bool signStrongName)
In there comment out the following code:

if (signStrongName)
{
byte[] keyPairStream = GetKeyPair();

         if (keyPairStream != null)
         {
             assemblyName.KeyPair = new StrongNameKeyPair(keyPairStream);
         }
     }

Now give it a shot.

Mario