Note: There is a new blog post based on this one, however you should read this one first to get an idea of the problems.I am trying out NHibernate in a medium trust environment using the built in DefaultProxy. However I get the following error:-
Operation could destabilize the runtime. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Source File: ProxyFactory.cs Line: 51 Stack Trace: [VerificationException: Operation could destabilize the runtime.] CmsContentProxy..ctor() +27 [TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98 System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241 System.Activator.CreateInstance(Type type, Boolean nonPublic) +69 System.Activator.CreateInstance(Type type) +6 NHibernate.Proxy.DynamicProxy.ProxyFactory.CreateProxy(Type instanceType, IInterceptor interceptor, Type baseInterfaces) in ProxyFactory.cs:51 NHibernate.Proxy.DefaultProxyFactory.GetProxy(Object id, ISessionImplementor session) in DefaultProxyFactory.cs:20Line 51 within the NHibernate sources:-
/Proxy/DyanmicProxy/ProxyFactory.cs line 51 object result = Activator.CreateInstance(proxyType);Things I have tried:-
1. Castle Proxy - They have created a proxy for 3.1 and not 3.2. I have looked at the NHibernate sources for both 3.1 and 3.2 but the interface to implement has changed.
2. Googled how to work around this problem but to no avail
3. Asked the question on NHusers user group.
I could wait to see if the castle/linfu/spring teams release a proxy that is compatible with version 3.2 however it would be nice to identify the problem within NHibernate itself so as I don't need a dependency on a third party proxy.
If anyone is interested in helping me I have provided a policy.config file, all you need to do is to place it in your web root and place this in your web.config.
<securityPolicy> <trustLevel name="Custom" policyFile="policy.config" /> </securityPolicy> <trust level="Custom" originUrl="" />I really would love to get this NH3.2 running in Medium trust as I love the new mapping by code syntax, any ideas, pointers, workarounds will be gratefully received.
I can see that Spring has now updated there framework so as to be compatible with NH3.2 GA, I will try this next...