Com And Hosting

As you might know iTextsharp is one of the most popular opensource library for PDF printing in ASP.NET website. Recently I have come across with the security issue running iTextsharp in shared hosting in GoDaddy. I was getting error –

“Medium trusted callers or partially trusted callers assembly are not allowed in sharedhosting – System.Security.SecurityException: That assembly does not allow partially trusted callers”

To fix this error I had to modify the AssemblyInfo.cs file to include assembly [assembly: AllowPartiallyTrustedCallers] then compile it to dll file. Unfortunately you cannot compile your package in Visual Web Developer 2010 or earlier version. You need Visual Studio.NET to compile your project or package into dll file.

This is what I have done to compile the iTextsharp source code into iTextsharp.dll using Visual Studio 2008 tools for application.

First download the latest iTextsharp source code from here. Once download finished then unzip the file and you will see a few zip files inside the main folders. See the folder structure for the version I have downloaded.

Now unzip the itextsharp-src-core file and you will see the following files and folders inside this folder. Visual Studio 2008 tools for application comes with windows 7, double click on the itextsharp.sln solution file and you will get the following options if you don’t have visual studio installed.

You might get a conversion wizard if you have downloaded old itextsharp source code. If it prompts for upgrade just go through the wizard it will basically convert the code into latest framework.

The wizard also creates a backup of your original source code if you click Yes in the wizard step. Once conversion finished Visual Studio 2008 tools will open the project with explorer like the screen capture below –

Now double click on Assembly.cs file to open and add the following line in the top section of the page –

using System.Security;
//to allow partially trusted callers
[assembly: AllowPartiallyTrustedCallers]

The source code will look like below after adding these lines –

Now right click on the project name and click on Build, this will basically create a dll file under the bin directory. Interesting it does not display the bin folder in the file explorer, so you close the Visual Studio Tools and check the file location you will find the bin folder there like below –

Hope this helps. Happy programming.

One thought on “Compiling dynamic link library (DLL) file using Visual Studio 2008 tools for application”
  1. Hello There

    How are you?

    I did the same above steps, created a new DLL file and uploaded to my shared hosting GoDaddy account. The same exact error as though what has been done doesn’t really exist.

    Error:

    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.

    I have been working on this web app for 3 months and without the PDF reports it is of no value whatsoever. I really need the help.

    Thanks
    Awny

Leave a Reply

Your email address will not be published.