安全透明方法'PayPal.UserAgentAeader.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中。
我可以使用任何全局设置来绕过此异常吗?
答案 0 :(得分:14)
将以下标记添加到web.config:
<configuration>
<system.web>
<trust level="Full" />
</system.web>
</configuration>
托管服务上的服务器可能设置为中等信任级别。 'PayPalCoreSDK'要求您的应用程序以完全信任级别运行。
答案 1 :(得分:6)
将此添加到assemblyinfo.cs
// added because of security transparency change in framework 4.0
[assembly: SecurityRules(SecurityRuleSet.Level1)]
这为我做了工作....
答案 2 :(得分:1)
将wpftoolkit 3.5框架升级到4.6.1框架后,assemblyinfo.cs中的以下安全规则解决了这个问题:
// added because of security transparency change in framework 4.0
[assembly: SecurityRules(SecurityRuleSet.Level1)]
答案 3 :(得分:0)
在我的情况下,当我在解决方案中管理NuGet包时,一些包覆盖了主网站项目中的System.Web.Mvc程序集版本绑定。设置回4.0.0.0(我安装了5.0)。我没有注意到更改,因为安装了Mvc v4.0并可通过GAC访问。退后
答案 4 :(得分:0)
我正在开发一个棕色地块应用程序,在解决方案中有很多引用的项目。一个项目设置为.NET 4.0而不是4.6.1,我认为可能是它,但这不是问题。我不得不补充道:
[assembly:AllowPartiallyTrustedCallers]
到包含“安全关键”方法的项目中的assembly.cs文件中,在我添加
之前我对此不满意using System.Security;
这就是诀窍。
乔伊