【问题标题】:Attempt by security transparent method to access security critical method failed尝试通过安全透明方法访问安全关键方法失败
【发布时间】:2013-12-13 16:29:18
【问题描述】:

尝试通过安全透明方法“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.

This stackoverflow answer 提到将[SecuritySafeCritical] 属性添加到类中,但在这种情况下,起作用的类位于通过 NuGet 加载的 DLL 中。

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

【问题讨论】:

    标签: c# asp.net paypal


    【解决方案1】:

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

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

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

    【讨论】:

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

    将其添加到 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)]
      

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          【解决方案5】:

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

           [assembly:AllowPartiallyTrustedCallers]
          

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

          using System.Security;
          

          成功了。

          乔伊

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-03-15
            • 1970-01-01
            • 2014-06-09
            • 2014-11-06
            • 2013-10-04
            • 2015-06-20
            相关资源
            最近更新 更多