Andreas Andreas - 3 months ago 30
C# Question

Assembly does not allow partially trusted caller

How do I change my library to allow partially trusted callers?

I get the following error:

Server Error in '/' Application.

Security Exception

Description: The application attempted
to perform an operation not allowed by
the security policy. To grant this
application the required permission
please contact your system
administrator or change the
application's trust level in the
configuration file.

Exception Details:
That assembly does not allow partially
trusted callers.

Source Error: [No relevant source

Source File: App_Web_kzj7vfkn.2.cs

Line: 0


After some more looking at the problem it seems like it's System.Web.UI.ClientScriptManager that causes the problem


Assuming you have access to the sources of your library.

  • Give the library you are trying to call a strong name.
  • Add [assembly:AllowPartiallyTrustedCallers] to the library that you are trying to call.
  • Create a code group to set permissions to the library

A pretty good and detailed explanation is given here Also read the links at the bottom to get a better understanding.

There is a possibility that not your assembly is the problem but you are calling another assembly that does not allow partially trusted callers. At runtime you can use fuslogvw to find which assembly is giving you the problems. If this is the problem and you have the sources of this assembly you need to also apply the [assembly:AllowPartiallyTrustedCallers] attribute to that assembly, if you don't have the sources the only option I know of is to replace the troublesome library.