尝试通过安全透明方法访问安全关键方法失败 [英] Attempt by security transparent method to access security critical method failed

查看:28
本文介绍了尝试通过安全透明方法访问安全关键方法失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试通过安全透明方法PayPal.UserAgentHeader.get_OperatingSystemFriendlyName()"访问安全关键方法System.Management.ManagementObjectSearcher..ctor(System.String)"失败.

程序集 'PayPalCoreSDK, Version=1.4.1.0, Culture=neutral, PublicKeyToken=null' 是部分受信任的,这会导致 CLR 使其完全安全透明,而不管程序集本身是否有任何透明注释.为了访问安全关键代码,必须完全信任此程序集.说明:在执行当前 Web 请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息.异常详细信息:System.MethodAccessException:尝试通过安全透明方法PayPal.UserAgentHeader.get_OperatingSystemFriendlyName()"访问安全关键方法System.Management.ManagementObjectSearcher..ctor(System.String)"失败.程序集 'PayPalCoreSDK, Version=1.4.1.0, Culture=neutral, PublicKeyToken=null' 是部分受信任的,这会导致 CLR 使其完全安全透明,而不管程序集本身是否有任何透明注释.为了访问安全关键代码,必须完全信任此程序集.

此 stackoverflow 答案 提到添加 [SecuritySafeCritical] 类的属性,但在本例中,该类位于通过 NuGet 加载的 DLL 中.

是否有任何全局设置可以用来绕过此异常?

解决方案

将以下标记添加到您的 web.config:

<预><代码><配置><system.web><trust level="Full"/></system.web></配置>

您的托管服务上的服务器可能设置为中等信任级别.PayPalCoreSDK"要求您的应用程序以完全信任级别运行.

Attempt by security transparent method 'PayPal.UserAgentHeader.get_OperatingSystemFriendlyName()' to access security critical method 'System.Management.ManagementObjectSearcher..ctor(System.String)' failed.

Assembly 'PayPalCoreSDK, Version=1.4.1.0, Culture=neutral, PublicKeyToken=null' is partially trusted, which causes the CLR to make it entirely security transparent regardless of any transparency annotations in the assembly itself.  In order to access security critical code, this assembly must be fully trusted.

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.

Exception Details: System.MethodAccessException: Attempt by security transparent method 'PayPal.UserAgentHeader.get_OperatingSystemFriendlyName()' to access security critical method 'System.Management.ManagementObjectSearcher..ctor(System.String)' failed.

Assembly 'PayPalCoreSDK, Version=1.4.1.0, Culture=neutral, PublicKeyToken=null' is partially trusted, which causes the CLR to make it entirely security transparent regardless of any transparency annotations in the assembly itself.  In order to access security critical code, this assembly must be fully trusted.

This stackoverflow answer mentions adding the [SecuritySafeCritical] attribute to the class, but in this case the class at play is in a DLL loaded through NuGet.

Are there any global settings I can use to bypass this exception?

解决方案

Add the following tag to your web.config:

<configuration>
    <system.web>
       <trust level="Full" />
    </system.web>
</configuration>

The servers on your hosting service is probably setup with a medium trust level. The 'PayPalCoreSDK' is requires your application to run with a full trust level.

这篇关于尝试通过安全透明方法访问安全关键方法失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆