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:-
<system.web>
  <securitypolicy>
    <trustlevel name="Custom" policyFile="policy.config" />
  </securityPolicy>
  <trust level="Custom" originUrl="" />
</system.web>
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.

2 comments:

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

    Below is my config section:


    NHibernate.Dialect.MsSql2005Dialect
    NHibernate.Connection.DriverConnectionProvider

    MY_CONNECTION_STRING





    And my trust settings:


    My Security Exception:
    [SecurityException: Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration, Version=4.0.0.0, 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?

    ReplyDelete
  2. trust level="Medium"

    i use default proxy factory integrated into 3.3.2

    ReplyDelete