In this article I will explain how to resolve the error System.Security.SecurityException: That assembly does not allow partially trusted callers when using iTextSharp Library DLL on a server that does not allow Full Trust to the Website.
Generally we face this issue when using Shared Hosting Servers and hence to resolve this issue we need to modify the iTextSharp DLL to allow partially trust callers.
 
 
1. Download the iTextSharp complete project
The very first step is to download the iTextSharp complete project and not just the DLL using the download link provided below.
 
 
2. Extract the downloaded Zip File
Next step is to extract the downloaded zip file.
iTextSharp System.Security.SecurityException: That assembly does not allow partially trusted callers
Inside the Root folder you will find many Zip files of which you need to extract the file shown in the below screenshot.
iTextSharp System.Security.SecurityException: That assembly does not allow partially trusted callers
 
 
3. Open the iTextSharp Project in Visual Studio
You will now be able to see the iTextSharp project files. Look for the Solution File and open the project in Visual Studio.
iTextSharp System.Security.SecurityException: That assembly does not allow partially trusted callers
 
Note: The project’s Framework is .Net 2.0 and hence you might need to upgrade the project.
 
 
4. Modify the AssemblyInfo.cs file
In the Solution Explorer window of Visual Studio, look for AssemblyInfo.cs file and open it as shown below.
iTextSharp System.Security.SecurityException: That assembly does not allow partially trusted callers
In this file you need to add the following line to enable Partial Trust support by the DLL as shown in the screenshot below.
[assembly: System.Security.AllowPartiallyTrustedCallers]
 
iTextSharp System.Security.SecurityException: That assembly does not allow partially trusted callers
 
 
5. Build the Project
Finally you need to build the project and then look for the updated DLL in the BIN folder of the project as shown below.
iTextSharp System.Security.SecurityException: That assembly does not allow partially trusted callers
Now this DLL is ready to be installed on your server.
 
 
Downloads

itextsharp.zip