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

C# 安全透明方法尝试访问安全关键方法失败,c#,asp.net,paypal,C#,Asp.net,Paypal,安全透明方法“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

安全透明方法“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.
提到将
[SecuritySafeCritical]
属性添加到类中,但在本例中,正在使用的类位于通过NuGet加载的DLL中


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

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

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


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

将其添加到assemblyinfo.cs

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

这为我完成了任务……

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

我当时正在开发一个棕地应用程序,解决方案中有很多被引用的项目。一个项目被设置为.NET4.0而不是4.6.1,我认为可能是这样,但这不是问题所在。我必须补充:

 [assembly:AllowPartiallyTrustedCallers]
在包含“security critical”方法的项目中的assembly.cs文件中,直到我还添加了

using System.Security;
这就成功了


Joey

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

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

谢谢你的回复。信任级别已处于完全级别。我通过签署DLL、调整一些安全敏感代码并重新编译它们来解决这个问题。我很高兴PayPal SDK是开源的,否则我会成为SOL!您能解释一下您是如何“调整了一些安全敏感代码”的吗?我现在遇到了这个问题,我的DLL已经签名,trust=full,但仍然无法正常工作。