Tuesday, May 01, 2012

Attempt by security transparent method 'xxxxxxxxx' to access security critical method 'xxxxxxxx' failed.


I converted my website to a web application and upgraded .net framework from v3.5 to v4. I also setup a class library to host entity framework models for the web app to consume. At run time when the business logic calls the entity framework class library I got this error below.

Attempt by security transparent method 'xxxxxxxxx' to access security critical method 'xxxxxxxx' failed.

Assembly 'xxxxxxxxxxx' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model.  Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.

 The solution is to specify the security level in the business logic project AssemblyInfo.cs, add the following line:
[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]


 

No comments: