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

c

i am creating pdf by using itextsharp.dll, local it is working fine. but server am facing below error .i have added assemblyinfo.cs ..but same error is coming.Specifically, I modified the AssemblyInfo.cs file by adding these references and attribute:

using System.Security;
using System.Security.Permissions;
[assembly: AllowPartiallyTrustedCallers]

in my form the pdf throws an error at myDocument.. It never go to read it n throws the below error…

  Document myDocument = new Document(PageSize.A4, 70, 70, 70, 70);

still am getting the error in server .. can anyone help me out

Server Error in '/' Application.
Security Exception
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.

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

Source Error:

Line 216: HttpContext.Current.Response.End();
Line 217:
Line 218: }
Line 219: protected void droplist_SelectedIndexChanged(object sender, EventArgs e)
Line 220: {

Source File: d:\hosting\bookgroupadmin\agent\checkbeforprintconf.aspx.cs Line: 218

Stack Trace:

[SecurityException: That assembly does not allow partially trusted callers.]
finalgroup_checkbeforprintconf.btn_Click(Object sender, EventArgs e) in d:\hosting\bookgroupadmin\agent\checkbeforprintconf.aspx.cs:218
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7350
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.checkbeforprintconf_aspx.ProcessRequest(HttpContext context) in App_Web_ovcuievo.18.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433

Best Answer

The best thing about it though is that it can run in Medium trust mode - once a minor change is made to allow partially trusted callers. To make this change download the iTextSharp source distribution (http://sourceforge.net/projects/itextsharp/files/) Modify the AssemblyInfo.cs file to add the partially trusted callers attribute.

[assembly: AllowPartiallyTrustedCallers()]

Rebuild the iTextSharp assembly and it should be good to go in a Medium trust environment.

Related Topic