2

I'm using NHibernate 3.3.1 in medium trust. It throw a Security Exception. In the NHibernate 3.3.1 say that it is compatible with medium trust.

Has it any prerequisite?

hazzik
  • 13,019
  • 9
  • 47
  • 86
Patrick Coelho
  • 158
  • 2
  • 14
  • I use NH3.3.1 in medium trust (Rackspace cloud), what is the actual error you are getting? – Rippo Jul 31 '12 at 07:17
  • The error is in portuguese: "Falha na solicitação da permissão de tipo 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'." – Patrick Coelho Aug 01 '12 at 00:50

4 Answers4

1

NHibernate supports medium trust, please read this article.

It describes how to achieve what you want.

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154
hazzik
  • 13,019
  • 9
  • 47
  • 86
1

I've had success using the NHibernate.DependencyInjection NuGet package to use NHibernate in a medium trust environment.

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154
  • I tryed it too... It added reference to the NHibernate.DependencyInjection.dll in my project but still throwing the SecurityException. Have it any prerequisite? – Patrick Coelho Jul 31 '12 at 17:40
  • 1
    @Rippo that's odd. Why would there be a package for 3.3.1 then? In any case, remember that not all "medium trust" configurations are the same. – Diego Mijelshon Aug 01 '12 at 14:26
  • That's a question you need to ask Randy, I believe he uses it for other reasons than for medium trust. https://nhibernate.jira.com/browse/NH-2857 – Rippo Aug 01 '12 at 15:26
  • Really, the trust configuration in my hosting aren't medium, it's custom. NH 3.31 worked. – Patrick Coelho Aug 02 '12 at 11:12
1

I had the same problem and tried all suggestion to fix it (including DependencyInjection), but only one helped me:

I've added following code to my Global.asax file

protected void Application_Start()
{
    NHibernate.Cfg.Environment.UseReflectionOptimizer = false;
    ...
}

And disabled batch in configuration file (last property)

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory name="NHibernate.Test">
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Server=........</property>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    <property name="query.substitutions">true=1;false=0</property>
    <property name="show_sql">false</property>
    <property name="adonet.batch_size">0</property>
  </session-factory>
</hibernate-configuration>

Note, this should cause performance issues

Maksim
  • 21
  • 1
  • For the "System.Security.Permissions.ReflectionPermission", using NHibernate or ActiveRecord, the first code with application start or AR initialization resolve the problem! This loved line "NHibernate.Cfg.Environment.UseReflectionOptimizer = false;" Thanks a lot! – diegodsp Jun 05 '18 at 23:14
0

You need to get a more detailed error message so we can diagnose further. In your web.config add this in the system.webserver

<httpErrors errorMode="Detailed"/>

Hopefully this will give you a full stack trace and from there should allow you to debug further.

You may also need to add this

<customErrors mode="Off" /> in system.web (I can't remember)

Rippo
  • 22,117
  • 14
  • 78
  • 117