Question

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?

Was it helpful?

Solution

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

OTHER TIPS

NHibernate supports medium trust, please read this article.

It describes how to achieve what you want.

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

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top