A Programmer’s Cheat-Sheet for GoDaddy.com

You’ve got your website running beautifully on your development / staging server. Then you upload your site to your GoDaddy Shared Hosting environment and are met with the ugly yellow screen of death and this message:

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

Here, I present the workarounds that I used to get my site up and running. These solutions apply to my use of MySQL and iTextSharp PDF library.

I hope you find this useful.


MySQL

Problem:
By default, the MySQL .NET Connector downloaded from the MySQL site requires full trust in order to work properly.

Solution:
Compile the connector so that Partially-Trusted callers can use the DLL.

Details:

  1. Download the source code for the connector.
  2. Modify the DLL attributes in the AssemblyInfo.cs file.
  3. add a using:  using System.Security;
  4. Add the following line to the file:[assembly: AllowPartiallyTrustedCallers]
  5. Compile the DLL.
  6. Upload to site and test.

Resources:
MySQL Connector Source Code

Problem:
The MySQL .NET required Admin level rights in order to execute stored procedures.

Solution:
Use ad-hoc queries to execute the stored procedure.

Details:

  1. Create the stored procedures in your database. You can do this via the phpMyAdmin in the GoDaddy DB console. Or, you can do as I do: create the stored procedure locally. Then send to a backup that contains only the new stored procs. Upload the backup to GoDaddy and start a restore. The proc will be created/updated on the GoDaddy server.
  2. Modify your .NET code. Create MySQLCommand objects with “Type=CommandType.Text”. The text will then be something along the lines of: “exec MyStoredProcName(‘Param1Value’, ‘Param2Value’)”
  3. Test your changes. Upload when you are ready.

Resources:

iTextSharp

Problem:
Ny default, the iTextSharp DLL only works in a Full-Trust environment.

Solution:
Recompile the connector so that it can be called by PartiallyTrusted Callers.

Details:

  1. Download the source code.
  2. Modify the DLL attributes in the AssemblyInfo.cs file (see above)
  3. Compile the DLL.
  4. Upload to site and test.

Resources:
iTextSharp source code (v4.1.2)

iTextSharp source code (v5.0.0)

I hope you have found this useful. If you have any questions or comments, please contact me.

Thanks for visiting my site!

5 Responses to A Programmer’s Cheat-Sheet for GoDaddy.com

  1. Jeff Meyer says:

    Thank-you Tomas! Of course I had to first reference System.Security in the AssemblyInfo.cs before [assembly: AllowPartiallyTrustedCallers] would work for iTextSharp.

    • -tomas says:

      (Sorry for the delay in acknowledging your observation)
      You are correct! The System.Security namespace is now required in Framework 4 in order to use the “AllowPartiallyTrustedCallers” assembly attribute.

      Thanks for pointing that out!

  2. Ahmad says:

    I am trying to use openXML SDK provided by microsoft on GoDaddy with no luck.

    I have no idea how to set the settings to run this thing on GoDaddy.

  3. Rajesh says:

    How to use the pdfsharp.dll like itextsharp.dll?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>