安全透明方法尝试访问安全关键方法失败。

9

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

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.

这个stackoverflow答案提到需要在类中添加[SecuritySafeCritical]属性,但在这种情况下,所涉及的类是通过NuGet加载的DLL。

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

5个回答

17

将以下标签添加到您的web.config文件中:

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

您的托管服务上的服务器可能设置为中等信任级别。 “PayPalCoreSDK”需要应用程序在完全信任级别下运行。


1
感谢您的回复。信任级别已经是完全的了。我通过对我的DLL进行签名,调整一些安全敏感的代码并重新编译它们来解决了这个问题。我很高兴PayPal SDK是开源的,否则我就会陷入困境! - Zerkey
2
你能否解释一下你是如何“调整了一些安全敏感的代码”的?我现在遇到了这个问题,我的DLL已经签名,信任级别为full,但仍然无法使其正常工作。 - antman1p

11

将此添加到assemblyinfo.cs中

// added because of security transparency change in framework 4.0
[assembly: SecurityRules(SecurityRuleSet.Level1)]

这对我起了作用....


3

将wpftoolkit 3.5框架升级到4.6.1框架后,以下在assemblyinfo.cs中的安全规则解决了这个问题:

// added because of security transparency change in framework 4.0
[assembly: SecurityRules(SecurityRuleSet.Level1)]

0

我正在处理一个包含许多引用项目的棕地应用程序。其中一个项目设置为.NET 4.0而不是4.6.1,我以为这可能是问题所在,但事实并非如此。我必须添加:

 [assembly:AllowPartiallyTrustedCallers]

在包含“安全关键”方法的项目中的assembly.cs文件中添加,直到我也添加了它,否则它不会满意。

using System.Security;

搞定了。

Joey


0
在我的情况下,当我在解决方案中管理NuGet包时,有一个问题是某个包覆盖了主网站项目中的System.Web.Mvc程序集版本绑定。将其设置回4.0.0.0(我安装了5.0)。我没有注意到这个变化,因为Mvc v4.0已经安装并可以通过GAC访问。将其设置回去即可。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接