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

Escort service in lucknow on :

Golden Chance in Lucknow We look forward to serving you independently in any of the hotel restaurants at affordable and sensual call girls categories. https://www.escortsserviceingurugram.co.in/call-girls-in-lucknow/

Jaipur Escorts on :

I really appreciate your post. Thanks for sharing such useful information. Thanks for sharing amazing information!

Add Comment

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