Tuesday 8 May 2012

NHibernate 3.3 and medium trust

With the new release of NHibernate 3.3 it seems from my early testing, that the Medium Trust issues have now disappeared and its good to see NHibernate 3.3 works in Medium Trust environments. I need to play with the NH Linq provider more to see what fails but from what I have seen so far I have to congratulate the NH development Team.

As a side note, if anyone is wondering how I test this then please download the modified medium trust file (called policy.config from Rackspace cloud) unzip it and save it to your web root folder.

Next simply add this to your web.config:-
    <trustlevel name="Custom" policyFile="policy.config" />
  <trust level="Custom" originUrl="" />
You now have a local development system running under medium trust. For those that do not run Rackspace cloud I would recommend asking your hosting provider for their medium trust policy file.

This is an update from a previous post when using NHibernate 3.2 (September 2011). The JIRA issue can be found here.


  1. Hello!
    I'm trying to run NHibernate 3.3.2 on Medium trust but it fails.

    Below is my config section:



    And my trust settings:

    My Security Exception:
    [SecurityException: Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed.]
    System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
    System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) +31
    System.Security.CodeAccessPermission.Demand() +46
    System.Configuration.BaseConfigurationRecord.CheckPermissionAllowed(String configKey, Boolean requirePermission, Boolean isTrustedWithoutAptca) +84

    What am I doing wrong?

  2. trust level="Medium"

    i use default proxy factory integrated into 3.3.2