These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Medium Trust and 1.2
PostPosted: Wed Mar 07, 2007 11:36 pm 
Newbie

Joined: Wed Mar 07, 2007 11:22 pm
Posts: 3
Hello,

I am attempting to get NHibernate to work in a medium trusted environment. I have read over every thread in this forum about getting this to work, but I seem to be missing something. I am using NHibernate version 1.2.0.CR1, and ASP.NET 2.0.

I am getting a ReflectionPermission exception

Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

when I call BuildSessionFactory on Configuration. I have set the lazy load property on the class to false, I am only using public properties, and I have set hibernate.use_reflection_optimizer to false.

Despite all of that, I am still getting the above exception. I have removed just enough code to still reproduce this issue. If anyone could help me resolve this issue, that would be great.

My mapping file
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="GamesLib.BusinessObjects.User, GamesLib" table="Users" lazy="false">
    <id name="UserId" type="Int64">
      <column name="UserId" />
      <generator class="identity" />
    </id>
    <property name="Email" type="String" />
    <property name="Password" type="String" />
  </class>
</hibernate-mapping>


My Class
Quote:
public class User {

public long UserId {
get { return _userId; }
set { _userId = value; }
}

public string Email {
get { return _email; }
set { _email = value; }
}

public string Password {
get { return _password; }
set { _password = value; }
}
//---------------------
private long _userId;
private string _email;
private string _password;
}


and finally,

The code I am using to build my session factory
Quote:
Configuration cfg = new Configuration();
cfg.SetProperty("hibernate.use_reflection_optimizer", "false");
cfg.SetProperty("hibernate.dialect","NHibernate.Dialect.MsSql2000Dialect");
cfg.SetProperty("hibernate.connection.provider","NHibernate.Connection.DriverConnectionProvider");
cfg.SetProperty("hibernate.connection.driver_class","NHibernate.Driver.SqlClientDriver");
cfg.SetProperty("hibernate.connection.connection_string",connectionString);
cfg.AddXmlFile(basePath + "User.hbm.xml");
_sessionFactory = cfg.BuildSessionFactory();


And it is that last line of that last code block that throws the exception.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 08, 2007 1:04 am 
Newbie

Joined: Wed Mar 07, 2007 11:22 pm
Posts: 3
Here is just a little more information that I have found out. I allowed the exception to dumb the stack trace to the browser, and here it is...

Quote:
[SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +59
System.Reflection.Emit.DynamicMethod.PerformSecurityCheck(Type owner, StackCrawlMark& stackMark, Boolean skipVisibility) +107
System.Reflection.Emit.DynamicMethod..ctor(String name, Type returnType, Type[] parameterTypes, Type owner, Boolean skipVisibility) +47
NHibernate.Bytecode.Lightweight.ReflectionOptimizer.CreateDynamicMethod(Type returnType, Type[] argumentTypes) +159
NHibernate.Bytecode.Lightweight.ReflectionOptimizer.GenerateGetPropertyValuesMethod(IGetter[] getters) +253
NHibernate.Bytecode.Lightweight.ReflectionOptimizer..ctor(Type mappedType, IGetter[] getters, ISetter[] setters) +127
NHibernate.Bytecode.Lightweight.BytecodeProviderImpl.GetReflectionOptimizer(Type mappedClass, IGetter[] getters, ISetter[] setters) +55
NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory) +6217
NHibernate.Persister.Entity.SingleTableEntityPersister..ctor(PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping mapping) +181
NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping cfg) +145
NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings) +1440
NHibernate.Cfg.Configuration.BuildSessionFactory() +111
GamesLib.ServiceLayer.Impl.Simple.SimpleSOImpl..ctor(String connectionString) +301
WebSite.ServiceObject.get_Current() +150
_Default.Page_Load(Object sender, EventArgs e) +72
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6953
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +154
System.Web.UI.Page.ProcessRequest() +86
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +18
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.default_aspx.ProcessRequest(HttpContext context) +46
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +154
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64




I am not sure what NHibernate is doing, nor how to fix it... but perhaps that strack trace means something to someone.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 08, 2007 1:40 am 
Newbie

Joined: Wed Mar 07, 2007 11:22 pm
Posts: 3
I think I have found a work around to the problem. Instead of using the SetProperty method of the Configuration object to set my configurations, I have moved them out to my web.config. This seems to have solved my issue.

portion of my web.config
Code:
  <configSections>
    <section name="nhibernate"
             type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"
             requirePermission="false" />
</configSections>
  <nhibernate>
    <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
    <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
    <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
    <add key="hibernate.connection.connection_string" value="server=SID\SQLEXPRESS; User ID=game;Password=password; database=games;Connect Timeout=2000;Application Name=FLUX;"/>
    <add key="hibernate.bytecode.provider" value="null" />
    <!-- Important under Medium Trust -->
  </nhibernate>


Creating my session factory
Code:
Configuration cfg = new Configuration();
cfg.AddAssembly("GamesLib");
_sessionFactory = cfg.BuildSessionFactory();


I pieced this together from this post: http://forum.hibernate.org/viewtopic.ph ... ight=trust

The only difference I could see between what I was doing, and what that poster was doing was that I was trying to programactically configure NHibernate. So, I attempted to just move that to the web.config and it looks like it works.

Is this perhaps a bug in NHibernate 1.2.0.RC1 that I should post somewhere?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.