Home

Castle Stronghold

Castle Project Forum Index Castle Project
Support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Lazy initialization and Medium trust level

 
Post new topic   Reply to topic    Castle Project Forum Index -> AR Usage
View previous topic :: View next topic  
Author Message
maxim



Joined: 11 Jun 2007
Posts: 13
Location: Kharkov, Ukraine

PostPosted: Thu Jun 14, 2007 9:09 am    Post subject: Lazy initialization and Medium trust level Reply with quote

I use lazy initialization for one of my classes, everything works fine but when I set <trust level="Medium"/> (medium trust is default level on my hosting) in the web.config file an exception appears:

Code:
Castle.ActiveRecord.Framework.ActiveRecordException

Message:
Could not perform FindByPrimaryKey for Message. Id: 51

StackTrace:
   at Castle.ActiveRecord.ActiveRecordBase.FindByPrimaryKey(Type targetType, Object id, Boolean throwOnNotFound)
   at Castle.ActiveRecord.ActiveRecordBase`1.Find(Object id)
   at Tipait.Board.Web.Controllers.MessagesController.Edit(Int32 id) in D:\Projects\Board\Web\Controllers\MessagesController.cs:line 102

Inner exception:
NHibernate.HibernateException

Message:
Creating a proxy instance failed

StackTrace:
   at NHibernate.Proxy.CastleProxyFactory.GetProxy(Object id, ISessionImplementor session)
   at NHibernate.Persister.Entity.AbstractEntityPersister.CreateProxy(Object id, ISessionImplementor session)
   at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation)
   at NHibernate.Impl.SessionImpl.Load(Type clazz, Object id)
   at Castle.ActiveRecord.ActiveRecordBase.FindByPrimaryKey(Type targetType, Object id, Boolean throwOnNotFound)

Inner exception:
System.Security.SecurityException

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

StackTrace:
   at System.Reflection.StrongNameKeyPair..ctor(Byte[] keyPairArray)
   at Castle.DynamicProxy.Builder.CodeGenerators.ModuleScope.CreateModule(Boolean signStrongName)
   at Castle.DynamicProxy.Builder.CodeGenerators.ModuleScope.ObtainDynamicModule(Boolean signStrongName)
   at Castle.DynamicProxy.Builder.CodeBuilder.EasyType..ctor(ModuleScope modulescope, String name, Type baseType, Type[] interfaces, Boolean serializable)
   at Castle.DynamicProxy.Builder.CodeGenerators.BaseCodeGenerator.CreateTypeBuilder(String typeName, Type baseType, Type[] interfaces)
   at Castle.DynamicProxy.Builder.CodeGenerators.ClassProxyGenerator.GenerateCode(Type baseClass, Type[] interfaces)
   at Castle.DynamicProxy.Builder.DefaultProxyBuilder.CreateClassProxy(Type theClass, Type[] interfaces)
   at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type baseClass, Type[] interfaces, IInterceptor interceptor, Boolean checkAbstract, Object[] argumentsForConstructor)
   at NHibernate.Proxy.CastleProxyFactory.GetProxy(Object id, ISessionImplementor session)


What should I do in this case?
Back to top
View user's profile Send private message
eneunaber



Joined: 14 Jun 2007
Posts: 2

PostPosted: Thu Jun 14, 2007 3:47 pm    Post subject: Reply with quote

I was going to post a question about "medium trust" level as well.

My hosting providing (Crystaltech) also has "medium trust" set as the default level. So when I try to do a simple SAVE I get this error:

Quote:
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.


So can ActiveRecord/nHibernate run on Medium Trust level?
Back to top
View user's profile Send private message
maxim



Joined: 11 Jun 2007
Posts: 13
Location: Kharkov, Ukraine

PostPosted: Thu Jun 14, 2007 3:57 pm    Post subject: Reply with quote

eneunaber, you have to rebuild castle source code and set AllowPartiallyTrustedCallers option (check build insturctions in the text file inthe root of the SVN repository)
Back to top
View user's profile Send private message
eneunaber



Joined: 14 Jun 2007
Posts: 2

PostPosted: Thu Jun 14, 2007 5:56 pm    Post subject: Reply with quote

I will give that a try, but I've never done a SVN checkout before. I've just downloaded the Binaries in the past. I was looking for some direction on the Castle site, but didn't find any other than go to: http://svn.castleproject.org:8080/svn/castle/trunk/ and you can use tortise to get the files.

I use tortise @ work, but when I try to download from castleproj, I'm not sure what protocal to use or what username/password to use.
Back to top
View user's profile Send private message
hammett
Castle Team


Joined: 15 Apr 2006
Posts: 1739
Location: SP, Brasil

PostPosted: Thu Jun 14, 2007 7:38 pm    Post subject: Reply with quote

Just copy that address and hit enter. No username or password is required.
_________________
Cheers,
hammett
http://hammett.castleproject.org/
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
maxim



Joined: 11 Jun 2007
Posts: 13
Location: Kharkov, Ukraine

PostPosted: Fri Jun 15, 2007 7:07 am    Post subject: Reply with quote

I think I have to use manual lazy load Sad
Back to top
View user's profile Send private message
maxim



Joined: 11 Jun 2007
Posts: 13
Location: Kharkov, Ukraine

PostPosted: Thu Jun 21, 2007 9:39 am    Post subject: Reply with quote

So, what about my first message in this topic?
Back to top
View user's profile Send private message
Avalon



Joined: 21 Nov 2006
Posts: 9

PostPosted: Thu Jun 21, 2007 3:06 pm    Post subject: Reply with quote

On as small note here, Crystal Tech allows you to be moved to a server with fully trusted permissions, Just ring thier support department.

Also I was lead to believe from an article on the nHibernate forums that Lazy Load can't be used with medium trust due to its reliance, through Dynamic Proxy on Reflection.

This article was quite old so i'm not sure if it still applies though (I don't have the link off hand, I'll have another look for it in a while)
Back to top
View user's profile Send private message
maxim



Joined: 11 Jun 2007
Posts: 13
Location: Kharkov, Ukraine

PostPosted: Wed Jun 27, 2007 12:04 pm    Post subject: Reply with quote

I think is not the best way to change hosting Smile A lot of people use hosting with medium trust level
Back to top
View user's profile Send private message
davidhardin



Joined: 01 Jul 2007
Posts: 1

PostPosted: Sun Jul 01, 2007 6:00 am    Post subject: Reply with quote

Actually CrystalTech uses a custom defined trust level. They took medium trust and opened up a few things like reflection. For more info see:

http://www.webcontrolcenter.com/Knowledge_Base/frmKB.aspx?KBID=913

I added the following to the medium trust file and now get the same results with my local server as I get on CrystalTech:

Code:
  <SecurityClasses>
     ...
     <SecurityClass Name="ReflectionPermission" Description="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  </SecurityClasses>

Then later in the file:

Code:
  <IPermission class="ReflectionPermission" version="1" Unrestricted="true"  />
  <IPermission class="WebPermission" version="1" Unrestricted="true" />


There are two other permissions I didn't worry about adding.
Back to top
View user's profile Send private message
mgavagha



Joined: 21 Aug 2007
Posts: 1

PostPosted: Tue Aug 21, 2007 5:38 pm    Post subject: NHibernate problems in medium trust Reply with quote

I can confirm Avalon's comment about NHibernate not working in a medium trust environment. I spent most of the weekend pulling my hair out and hacking the source code to make it work. Ultimately, I was stopped because my hosting provider denies ReflectionEmit - so NHibernate can't instantiate a dynamic method:
http://www.gavaghan.org/blog/2007/08/21/nhibernate-in-a-medium-trust-environment/

I was given the option of a dedicated server (too much $$$), so I found a shared host provider that provides full trust.

--Mike
Talk Nerdy To Me
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Castle Project Forum Index -> AR Usage All times are GMT
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group