NHibernate +远程处理 = ReflectionPermission 异常
当我们在完全信任环境的机器(实际上是我们的开发机器)中使用带有远程处理功能的 NHibernate 时,我们正在处理一个问题。
当尝试将先前从服务器检索到的对象作为参数发送时,会出现问题,该对象的属性之一(惰性属性)中包含 NHibernate 代理。
当我们在开发机器中时,Web 应用程序的信任级别没有限制(设置为“完全”),而且,作为一个优点,我们已将 NHibernate 和 Castle 的程序集配置为完全信任 CAS(甚至认为它“没有必要,因为 IIS 中的远程处理应用程序具有完全信任级别)。
有谁知道什么可能导致此异常?下面的堆栈跟踪。
InnerException: System.Security.SecurityException
Message="Falha na solicitação da permissão de tipo 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."
Source="mscorlib"
GrantedSet=""
PermissionState="<IPermission class=\"System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\r\nversion=\"1\"\r\nFlags=\"ReflectionEmit\"/>\r\n"
RefusedSet=""
Url=""
StackTrace:
em System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
em System.Security.CodeAccessPermission.Demand()
em System.Reflection.Emit.AssemblyBuilder.DefineDynamicModuleInternalNoLock(String name, Boolean emitSymbolInfo, StackCrawlMark& stackMark)
em System.Reflection.Emit.AssemblyBuilder.DefineDynamicModuleInternal(String name, Boolean emitSymbolInfo, StackCrawlMark& stackMark)
em System.Reflection.Emit.AssemblyBuilder.DefineDynamicModule(String name, Boolean emitSymbolInfo)
em Castle.DynamicProxy.ModuleScope.CreateModule(Boolean signStrongName)
em Castle.DynamicProxy.ModuleScope.ObtainDynamicModuleWithWeakName()
em Castle.DynamicProxy.ModuleScope.ObtainDynamicModule(Boolean isStrongNamed)
em Castle.DynamicProxy.Generators.Emitters.ClassEmitter.CreateTypeBuilder(ModuleScope modulescope, String name, Type baseType, Type[] interfaces, TypeAttributes flags, Boolean forceUnsigned)
em Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope, String name, Type baseType, Type[] interfaces, TypeAttributes flags, Boolean forceUnsigned)
em Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope, String name, Type baseType, Type[] interfaces, TypeAttributes flags)
em Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope, String name, Type baseType, Type[] interfaces)
em Castle.DynamicProxy.Generators.BaseProxyGenerator.BuildClassEmitter(String typeName, Type parentType, Type[] interfaces)
em Castle.DynamicProxy.Generators.BaseProxyGenerator.BuildClassEmitter(String typeName, Type parentType, IList interfaceList)
em Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[] interfaces, ProxyGenerationOptions options)
em Castle.DynamicProxy.Serialization.ProxyObjectReference.RecreateClassProxy()
em Castle.DynamicProxy.Serialization.ProxyObjectReference.RecreateProxy()
em Castle.DynamicProxy.Serialization.ProxyObjectReference..ctor(SerializationInfo info, StreamingContext context)
先感谢您。
We are dealing with a problem when using NHibernate with Remoting in a machine with full trust enviroment (actually that's our dev machine).
The problem happens when whe try to send as a parameter an object previously retrieved from the server, that contains a NHibernate Proxy in one of the properties (a lazy one).
As we are in the dev machine, there's no restriction in the trust level of the web app (it's set to Full) and, as a plus, we've configured NHibernate's and Castle's assemblies to full trust in CAS (even thinking that it'd not be necessary as the remoting app in IIS has the full trust level).
Does anyone have any idea of what can be causing this exception? Stack trace below.
InnerException: System.Security.SecurityException
Message="Falha na solicitação da permissão de tipo 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."
Source="mscorlib"
GrantedSet=""
PermissionState="<IPermission class=\"System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\r\nversion=\"1\"\r\nFlags=\"ReflectionEmit\"/>\r\n"
RefusedSet=""
Url=""
StackTrace:
em System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
em System.Security.CodeAccessPermission.Demand()
em System.Reflection.Emit.AssemblyBuilder.DefineDynamicModuleInternalNoLock(String name, Boolean emitSymbolInfo, StackCrawlMark& stackMark)
em System.Reflection.Emit.AssemblyBuilder.DefineDynamicModuleInternal(String name, Boolean emitSymbolInfo, StackCrawlMark& stackMark)
em System.Reflection.Emit.AssemblyBuilder.DefineDynamicModule(String name, Boolean emitSymbolInfo)
em Castle.DynamicProxy.ModuleScope.CreateModule(Boolean signStrongName)
em Castle.DynamicProxy.ModuleScope.ObtainDynamicModuleWithWeakName()
em Castle.DynamicProxy.ModuleScope.ObtainDynamicModule(Boolean isStrongNamed)
em Castle.DynamicProxy.Generators.Emitters.ClassEmitter.CreateTypeBuilder(ModuleScope modulescope, String name, Type baseType, Type[] interfaces, TypeAttributes flags, Boolean forceUnsigned)
em Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope, String name, Type baseType, Type[] interfaces, TypeAttributes flags, Boolean forceUnsigned)
em Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope, String name, Type baseType, Type[] interfaces, TypeAttributes flags)
em Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope, String name, Type baseType, Type[] interfaces)
em Castle.DynamicProxy.Generators.BaseProxyGenerator.BuildClassEmitter(String typeName, Type parentType, Type[] interfaces)
em Castle.DynamicProxy.Generators.BaseProxyGenerator.BuildClassEmitter(String typeName, Type parentType, IList interfaceList)
em Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[] interfaces, ProxyGenerationOptions options)
em Castle.DynamicProxy.Serialization.ProxyObjectReference.RecreateClassProxy()
em Castle.DynamicProxy.Serialization.ProxyObjectReference.RecreateProxy()
em Castle.DynamicProxy.Serialization.ProxyObjectReference..ctor(SerializationInfo info, StreamingContext context)
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,我与 Pedro 合作,我们发现了问题:远程服务的序列化器必须显式配置为允许服务器端的完全信任调用。
像(配置文件):
或者(以编程方式):
希望这对其他人有帮助。
问候。
Actually, I work with Pedro, we found the problem: the serializer of the Remoting Service has to be explicit configured to allow full trust calls in the server side.
Something like (configuration file):
Or (programatically):
Hope this helps anyone else.
Regards.