Nasir
Nasir

Reputation: 11451

C# - .NET 4.0 - That Assembly does not allow partially trusted callers

When running from a network share, my application throws the following exception:

That assembly does not allow partially trusted callers.

My application references two DLL files:

I'm not sure which one it is having problems with.

I've used CASPOL hack before, with .NET 3.5, however, it seems to not work with .net 4.0 now. Can anyone suggeest on how I can bypass this "Partially Trusted Caller" check?

Thanks.

Upvotes: 1

Views: 12939

Answers (1)

Jeffrey Hantin
Jeffrey Hantin

Reputation: 36534

.NET 4.0 has changed the default rules for security policy. You'll need to create or modify the App.config file for this application.

Code access security (as configured by CASPOL) is now ignored by default in .NET 4.0. If you want to enable it you need to add the following to your app.config file:

<configuration>
   <runtime>
      <!-- enables legacy CAS policy for this process -->
      <NetFx40_LegacySecurityPolicy enabled="true" />
   </runtime>
</configuration>

You can configure .NET 4.0 to treat code from the network using LoadFrom as fully trusted with the following configuration item:

<configuration>
   <runtime>
      <!-- Treat assemblies from network locations as fully trusted. -->
      <!-- Caution: Do not point this loaded gun at your foot. -->
      <loadFromRemoteSources enabled="true" />
   </runtime>
</configuration>

Upvotes: 13

Related Questions