Home > asp.net, Exceptions, Security > Run iTextSharp.dll under Medium Trusted Callers or Partially Trusted Callers

Run iTextSharp.dll under Medium Trusted Callers or Partially Trusted Callers

Problem:

Most programmers who are hosting websites on a shared hosting envoirment and using iTextSharp dll to create reports or invoices may face a problem as by default, the iTextSharp DLL only works in a Full-Trust environment.So it will work perfectly on local host but will give errors on online server.

Error:

The error you will get will be something like this.

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

Solution:

According to my knowledge the only solution to this problem is recompile the source code with edited attributes for assembly info so it will allow to work under partially trusted envoirment.

Step By Step:

  1. Download The source code
  2. Modify attributes in AssemblyInfo.cs
     Modify the DLL attributes in the AssemblyInfo.cs file. Add the following line to the file:[assembly: AllowPartiallyTrustedCallers]
       3.Compile the DLL
       4.Upload and test.
I faced this problem during one of my projects.So i thought it’s worth sharing and it will surely help someone.
If you guys have any problem regarding this please let me know how i can assist you.
Thanks for visiting.
Have a Blessed Day.
Advertisements
  1. jessica
    December 1, 2011 at 7:33 am

    Hi,

    I have download the itextsharp.dll v4.1.6.0 and add reference of the itextsharp.dll into my project. Next, adding the assembly: AllowPartiallyTrustedCallers into the AssemblyInfo.cs but still the security exception persists.

    Kindly advise

  2. December 1, 2011 at 7:40 am

    Hi
    Jessica don’t download the “dll” itextsharp.dll .
    Just download the source code for that dll from the links given below.And then add that AllowPartiallyTrustedCallers attribute in AssemblyInfo.cs for that source code of that iTextSharp source code and then re compile it.The the dll will be generated and will be placed in bin folder in the solution explorer then add refrence to that new dll into your project.
    I hope this will help.Good Luck!

  3. February 3, 2012 at 9:23 am

    Tanx for this info. Worked well for me! Changed, compiled, uploaded to hoster, security problem solved!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: