Zerkey
Zerkey

Reputation: 795

Attempt by security transparent method to access security critical method failed

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.

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 mentions adding the [SecuritySafeCritical] attribute to the class, but in this case the class at play is in a DLL loaded through NuGet.

Are there any global settings I can use to bypass this exception?

Upvotes: 9

Views: 22551

Answers (5)

Arun
Arun

Reputation: 31

After upgrading wpftoolkit 3.5 framework to 4.6.1 framework, the below Security rules in assemblyinfo.cs resolve the issue:

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

Upvotes: 3

Joey Morgan
Joey Morgan

Reputation: 913

I was working on a brownfield application with a lot of referenced projects in the solution. One project was set to .NET 4.0 instead of 4.6.1 and I thought that might be it, but that wasn't the issue. I had to add:

 [assembly:AllowPartiallyTrustedCallers]

to the assembly.cs file in the project containing the "security critical" method, and it wasn't happy with me until I also added

using System.Security;

That did the trick.

Joey

Upvotes: 0

wałdis iljuczonok
wałdis iljuczonok

Reputation: 662

In my case it was an issue when I managed a NuGet packages in the solution some package overrides System.Web.Mvc assembly version binding in main web site project. Set back to 4.0.0.0 (I had 5.0 installed). I didn't change notice the change because Mvc v4.0 was installed and accessible via GAC. Set back

Upvotes: 0

doubleotwo
doubleotwo

Reputation: 111

adding this to assemblyinfo.cs

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

this did the job for me ....

Upvotes: 11

Mark Smith
Mark Smith

Reputation: 189

Add the following tag to your web.config:

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

The servers on your hosting service is probably setup with a medium trust level. The 'PayPalCoreSDK' is requires your application to run with a full trust level.

Upvotes: 18

Related Questions