简体   繁体   中英

XMLWorkerHelper does not contain a constructor that takes 0 arguments in c#

在此处输入图像描述 i am trying to pdf generate using html template in mvc4 and i have adding xmlworker packages and write a following code. i will build my solution then show in following error. XMLWorkerHelper does not contain a constructor that takes 0 arguments Please suggest me... Controller:-

 public void abcd()
            {
                try
                {
                    string UniqueNumber = Request.QueryString["UniqueNumber"];
                    string strFileName = UniqueNumber;
                    string strFileExtension = ".pdf";
                    string strContentType = FileManager.FileContentType_application_pdf;
                    string strExportData = string.Empty;
                    Document pdfDoc = new Document(PageSize.A4, 43f, 50f, 5f, 50f);
                    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                    var output = new MemoryStream();
                    StringWriter sw = new StringWriter();
                    XMLWorkerHelper htw = new XMLWorkerHelper();
                    StringReader sr;
                    sr = new StringReader(Convert.ToString(ExportData.UserDetails(UniqueNumber)));
                    PdfWriter.GetInstance(pdfDoc, output);
                    pdfDoc.Open();
                    htmlparser.Parse(sr);
                    pdfDoc.Close();
                    strFileName = strFileName.Replace(" - ", "-").Replace(" ", "-").Replace("--", "-");
                    Response.ClearContent();
                    Response.Buffer = true;
                    Response.AddHeader("content-disposition", string.Format("attachment; filename={0}{1}",                 strFileName, strFileExtension));
                    Response.ContentType = strContentType;
                    Response.Charset = "";
                    Response.BinaryWrite(output.ToArray());
                    Response.Flush();
                    Response.End();

                }
                catch (Exception ex)
                {
                    //

                }
            }

It looks like the Singleton pattern is used within this assembly Dip.

Please replace your current code, XMLWorkerHelper htw = new XMLWorkerHelper(); with this XMLWorkerHelper htw = XMLWorkerHelper.GetInstance(); and give it a shot.

As a side note, you may want to look into the IDisposable interface. Check if any of the objects your are "newing" up implement it and dispose of them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM