数据=无法评估表达式,因为代码已优化或本机框架位于调用堆栈的顶部. [英] Data = Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

查看:92
本文介绍了数据=无法评估表达式,因为代码已优化或本机框架位于调用堆栈的顶部.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  string 附件= " ;
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.AddHeader(" ,附件);
        HttpContext.Current.Response.ContentType = " ;
        StringWriter stw =  StringWriter();
        HtmlTextWriter htextw =  HtmlTextWriter(stw);
        文档doc =  Document(iTextSharp.text.PageSize.A4, 30  50 // 字符串路径= Server.MapPath("PDFs"); 
        PdfWriter.GetInstance(doc,HttpContext.Current.Response.OutputStream);
        数据表dt = emp.SelectEmployeeWithDesgnDeptLocComp(empid);
        doc.Open();
        Paragraph paradheader =  Paragraph();
        paragageheader.SpacingAfter = 1f;
         float  [] headercols = {1f,2f, 1  .2f,2f};
        PdfPTable table =  PdfPTable(headercols);
        table.WidthPercentage = 100f;
        PdfPCell单元格= GetFormName(company);





  StringReader str =  StringReader(stw.ToString());
        HTMLWorker htmlworker =  HTMLWorker(doc);
        htmlworker.Parse(str);
        doc.Close();
        HttpContext.Current.Response.Write(doc);
        HttpContext.Current.Response.End();

// 数据=由于代码已优化或本机框架位于调用堆栈的顶部,因此无法评估表达式. 

解决方案

好.

代替Response.End,您必须使用HttpContext.Current.ApplicationInstance.CompleteRequest方法将代码执行绕过到Application_EndRequest事件.

在此处查看详细信息: Microsoft支持:如果您使用Response.End,Response.Redirect或Server.Transfer,则会发生ThreadAbortException [ ^ ]

string attachment = "attachment; filename=FormA5.pdf";
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.AddHeader("content-disposition", attachment);
        HttpContext.Current.Response.ContentType = "application/pdf";
        StringWriter stw = new StringWriter();
        HtmlTextWriter htextw = new HtmlTextWriter(stw);
        Document doc = new Document(iTextSharp.text.PageSize.A4, 30, 30, 50, 50);
        //string path = Server.MapPath("PDFs");
        PdfWriter.GetInstance(doc, HttpContext.Current.Response.OutputStream);
        DataTable dt = emp.SelectEmployeeWithDesgnDeptLocComp(empid);
        doc.Open();
        Paragraph paragraphheader = new Paragraph();
        paragraphheader.SpacingAfter = 1f;
        float[] headercols = { 1f, 2f, 1.2f, 2f };
        PdfPTable table = new PdfPTable(headercols);
        table.WidthPercentage = 100f;
        PdfPCell cell = GetFormName(company);





  StringReader str = new StringReader(stw.ToString());
        HTMLWorker htmlworker = new HTMLWorker(doc);
        htmlworker.Parse(str);
        doc.Close();
        HttpContext.Current.Response.Write(doc);
        HttpContext.Current.Response.End();

//Data = Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

解决方案

Ok.

In place of Response.End you have to use HttpContext.Current.ApplicationInstance.CompleteRequest method to bypass the code execution to the Application_EndRequest event.

Look here for details: Microsoft Support: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer[^]


这篇关于数据=无法评估表达式,因为代码已优化或本机框架位于调用堆栈的顶部.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆