Tuesday, March 13, 2012

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

I developed a web site using .net 2.0, mysql 4.0 and IIS 5.0. The server is hosted by a third party.

I am using the MySql.Data.dll library version 5.0.7.0 to connect to the database. I did not create any custom assembly and I am using the MySqlData objects directly from the code:

using MySql.Data.MySqlClient;


MySqlConnection conn;
MySqlDataAdapter data_retriever;
DataTable TextDataTable;

TextDataTable = new DataTable();

data_retriever = new MySqlDataAdapter(last_query_executed.Value.ToString(), conn);

data_retriever.Fill(TextDataTable);

This is the error I get:

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

[SecurityException: That assembly does not allow partially trusted callers.]
search_search.BindData() +0
search_search.Page_Load(Object sender, EventArgs e) +30
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6978
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +213
System.Web.UI.Page.ProcessRequest() +86
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +18
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.search_search_aspx.ProcessRequest(HttpContext context) +4
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +303
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

My level of knowledge of .NET and Visual Studio is not advanced.

Do you have any suggestions?

Thanks,

Christian

Here is a post on the issue. It seems the current server configuration does not allow partial trusted callers.

http://bloggingabout.net/blogs/rick/archive/2006/04/07/11929.aspx -- this may not really apply becaus eyour site is hosted by a 3rd party

http://forums.mysql.com/read.php?38,95478,96748#msg-96748 -- has a link to download a new version of MySql assembly allowing partial trust. Not sure it will work, mixed results

http://forums.asp.net/t/999456.aspx -- has some other solutions. One of which is using a ODBC connection to MySql instead.

http://dev.mysql.com/tech-resources/articles/dotnet/ --see for ODBC driver details


I tried to recompile the library. However, I get a compilation error after I add the following line in the Assemplyinfo.cs:

[assembly: AllowPartialllyTrustedCallers]

Any ideas?

Christian


What error did you get? Also post your AssemblyInfo.cs file.


I fixed this problem, I was missing the following line:

using

System.Security;

however, now i am getting the error:

Unable to connect to any of the specified MySQL hosts.

0 comments:

Post a Comment