Skip Navigation LinksHome > Articles > Asp.net > System.Security.SecurityException: That assembly does not allow partially trusted callers

System.Security.SecurityException: That assembly does not allow partially trusted callers

How to solve partially trusted callers dll issues

By Keyur   On   Thursday, 28 January 2010

Page Views : 539   |   Technologies : Asp.net

Rating : Rated :
0

That assembly does not allow partially trusted callers

In this article I will explain what this error is and how to work around it.

 

So first of all what is this error all about?

By default, ASP.NET 2.0 Web applications and Web services run with full trust and applications can perform privileged operations and access resources subject only to operating system security and Windows access control lists (ACLs).

 

To lock down an ASP.NET application and to provide an additional level of application isolation in a hosted environment, you can use code access security to restrict the resources the application can access and the privileged operations it can perform. You do this by configuring the <trust> element as shown here.

 

<trust level="Medium" originUrl="" />

 

Due to this reason your hosting environment will not allow to make calls to partially  trusted callers.  Usually when you are hosting with GoDaddy they run all their applications in medium trust level and in that case you will face too many issues while deploying your applications. Let’s say you have created 3 different DLL projects as Model/DataAccess/BusinessLogic in your web application and referenced them into your ASP .NET web application.

 

And if you try to run this application under medium trust it will start throwing this same exception. The solutions to this problem are as below.

 

First:-

 

<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" requirePermission="false" />

 

 

I have taken the example of Enterprise Library V. 3.1 because those assemblies are also signed and do not allow partially trusted callers. If you are using the same I have attached those DLL after recompiling and you can download and resuem them immediately. If you want to do it your self I have defined steps to do that under Notes section.

 

But sometimes this will not be enough as in the shared webhosting environment they usually lock this section to be overridden=false. In that case our solution above will not work.

 

Second:-

 

1) Open the AssemblyInfo.cs file of your DLL projects and add following using statement. 

using System.Security;

 

2) Add following line at appropriate place.

[assembly: AllowPartiallyTrustedCallers()]

 

That’s it. Recomiple this dlls and redeploy your projects. This error should be solved.

 

This is possible when you are using your own DLLs or some open source DLL whose source is publicly available and you can download and modified as shown below.

 

Note : -

Sometimes you happen to use Enterprise Library for data access(DAAB) and logging ,etc. As I mentioned above version 3.1 of Enterprise Library has similar issue. In order to solve this issue you have to do two steps.

 

1) Download ObjectBuild project source code from codeplex.

 

2) Leave it unsigned or add AllowPartiallyTrustedCallers  attribute to it and recompile.

 

3) Take this new DLL and open your EnterPriseLibrary v 3.1 source code solution and re-add references in all the projects where this ObjectBuilder.dll is refered. Also leave those projects DLL as unsigned or add the [assembly: AllowPartiallyTrustedCallers()] attribute to them and recompile.

 

4) Take all these new DLLs and add them to your project and redeploy. It should work without any issues.

 

For your convenience I have recompiled the ObjectBuilder and DAAB DLLs as described above.

 

Feel free to download and use them. Please post your comments if you have any question/concerns.

Thanks.


Keywords : IBuilderPolicy
CloneParameter
IPropertySetterInfo
PropertySetterStrategy
DependencyMissingException
InjectionConstructorAttribute
DependencyAttribute

Tags : System.Security.SecurityException: That assembly does not allow partially trusted callersASP .Net Medium trustShared Hosting Godaddy - partially trusted caller
Rate This Article :

Comments :

# 1 shashankb Wrote on 07/07/2010


Thanks for the great article. I have been struggle with this very issue for past couple of days to deploy code on GoDaddy server. Where can I find the download mentioned in this article?



# 2 Keyur Wrote on 07/19/2010


You are welcome. Once you are logged in on the website you will see download button at the top of the article. Click that button and you should be able to download it.



Write a Comment / Question / Feedback ...


User Login
Username :
Password :
Register Login

Forgot Password


Related Articles