簡體   English   中英

嘗試通過安全透明方法訪問安全關鍵方法失敗

[英]Attempt by security transparent method to access security critical method failed

嘗試使用安全透明方法'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中。

我可以使用任何全局設置來繞過此異常嗎?

將以下標記添加到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)]

這為我完成了這項工作....

將wpftoolkit 3.5框架升級到4.6.1框架后,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訪問。 退后一步

我正在開發一個棕色地塊應用程序,在解決方案中有很多引用的項目。 一個項目設置為.NET 4.0而不是4.6.1,我認為可能是它,但這不是問題。 我不得不補充:

 [assembly:AllowPartiallyTrustedCallers]

到包含“安全關鍵”方法的項目中的assembly.cs文件,在我添加之前它對我不滿意

using System.Security;

這就是訣竅。

喬伊

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM