Skip to content

Exception: That assembly does not allow partially trusted callers

I have .net 3.5 program where i load some assemblies from a network share via reflection. Now i've got the following exception: "That assembly does not allow partially trusted callers''(Detailed message below). The calling assembly(.exe) is local. This .exe loads the assembly from network via reflection. The assembly from the network share then has a reference on a third assembly which is located beneath the .exe. (Hard to explain, image will do better...)

The reason for this failure is the .net security. It doesn't allow the MyLib.dll to be loaded, because the calling assembly is located on a network share and is signed with a strong name.

Solution 1, caspol.exe Allow all code to be executed. This might be dangerous, but if you're desperate it could be a solution.

 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\CasPol.exe" -machine -chggroup All_Code FullTrust

Solution 2, no signing If you remove the signature from MyLib2.dll, everything works.

Solution 3, set attribute AllowPartiallyTrustedCallers If you set the AllowPartiallyTrustedCallers in the AssemblyInfo.cs of the signed assembly, everything works.

using System.Security;

[assembly: AllowPartiallyTrustedCallers()]

Usefull links

Full exception(for google):

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'PermissionCaspolTestLibSigned, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'PermissionCaspolTestLibSigned, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
   at PermissionCasplTestLib.Class1..ctor()

WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

--- End of inner exception stack trace --- at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at PermissionCaspolTest.Program.DoSth() ----- Inner Exception ----- System.IO.FileNotFoundException: Could not load file or assembly 'PermissionCaspolTestLibSigned, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. File name: 'PermissionCaspolTestLibSigned, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' at PermissionCasplTestLib.Class1..ctor()

WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

jerry on :

thanks

Steve on :

Awesome, no one broke it out as well as you.

Purchase Custom Papers Online on :

You should be cautious what gatherings in the .NET framework that you use in somewhat trusted congregations, as various them can't be called from in part confided in code. This incorporates essentially anything that could be viewed as a noteworthy security chance, i,e, access to the document framework, occasion log and system settings.

JavaHelpOnline.com on :

Things Are Very Open And Intensely Clear Explanation Of Issues. Was Truly Information. Your Website Is Very Beneficial.

LawAssignmentsHelp.com on :

This Is Really Great Work. Thank You For Sharing Such A Good And Useful Information Here In The Blog For Students.

Marketing Project Help Service on :

I Am So Happy To Read This. This Is The Kind Of Manual That Needs To Be Given And Not The Random Misinformation That's At The Other Blogs.

Do My Medical Thesis Writing on :

Well Thanks For Posting Such An Outstanding Idea. I Like This Blog & I Like The Topic And Thinking Of Making It Right.

Hadi Tabbal Jacket on :

A low-level computing construct, frequently shortened asm, is any low-level programming dialect, in which there is an extremely solid correspondence between the get-together program proclamations and the design's machine code directions

Add Comment

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Markdown format allowed
Form options