Wednesday 30 March 2016

[Solved] Attempt by security transparent method '.‏‫ while using dll

While i was trying to use a dll in my application it was giving me error like this.

Attempt by security transparent method '<Module>.‏‫‌​‮‍‍‬‭‪‪‌‪‌‪‏​‎‪‍‌‬‪‮()' to access security critical method 'System.AppDomain.add_AssemblyResolve(System.ResolveEventHandler)' failed.

Assembly 'xxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 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.

let me tell you, i had my dll in place all was working file but when i encoded my dll using confuserEx it stoped working and thown an error.

I solved this issue by adding given code into assemblyinfo.cs

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


or

<trust level="Full" />