apekhsa
apekhsa

Reputation:

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

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

Upvotes: 4

Views: 12869

Answers (4)

Nripendra Ojha
Nripendra Ojha

Reputation: 375

I also faced this type problem and resolved by follow the instruction of below link. it is so helpful it save my 3 days hard work. You can try this

https://www.aspsnippets.com/Articles/ASPNet-iTextSharp-SystemSecuritySecurityException-That-assembly-does-not-allow-partially-trusted-callers.aspx

Last 2 more step doing by me which is not mentioned 1. Remove old reference of iTextsharp from your project. 2. Add new iTextsharp dll reference in your project. which is make by you. Then publish your project. Do not directly paste the new itextsharp.dll in your server with old publish code.

Upvotes: 0

Chathura
Chathura

Reputation: 11

I got the same issue and it has solved by creating another folder, move all the contents to that and change the application path to the new folder. I can't say that how it solved fore sure. But it worked for me. I believe it has due to some caching issue in IIS.

Hope this will help you guys.

Upvotes: 1

Dotneter
Dotneter

Reputation: 31

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.

Upvotes: 3

Slavo
Slavo

Reputation: 15463

Most probably the library that you use does not support a medium trust environment (most shared hosting companies). It might not be your code that throws the error, but the third party - make sure that they do support this.

If the stack trace ends in a portion of code written by you, then please provide this code, currently it is not clear what exactly doesn't have permissions to run.

Upvotes: 2

Related Questions