NHibernate +远程处理 = ReflectionPermission 异常

发布于 2024-08-29 21:36:47 字数 3094 浏览 6 评论 0原文

当我们在完全信任环境的机器(实际上是我们的开发机器)中使用带有远程处理功能的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏雪无痕 2024-09-05 21:36:47

实际上,我与 Pedro 合作,我们发现了问题:远程服务的序列化器必须显式配置为允许服务器端的完全信任调用。

像(配置文件):

<channels>
<channel ref="http">
<serverProviders> 
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel=Low />
<formatter ref="binary" typeFilterLevel=Low />
</serverProviders>
</channel>
</channels>

或者(以编程方式):

BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;

希望这对其他人有帮助。

问候。

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):

<channels>
<channel ref="http">
<serverProviders> 
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel=Low />
<formatter ref="binary" typeFilterLevel=Low />
</serverProviders>
</channel>
</channels>

Or (programatically):

BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;

Hope this helps anyone else.

Regards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文