0

I have an RDLC report that is generated in ASP.NET. The report is loaded into a report viewer hosted in an ASPX form.

The report is printed correctly if only English characters were written to it, if Arabic characters are added the report will be shown, however when I click the print button the following error is thrown:

Managed Debugging Assistant 'PInvokeStackImbalance' : 'A call to PInvoke function 'Microsoft.ReportViewer.Common!Microsoft.ReportingServices.Rendering.ImageRenderer.FontPackage::CreateFontPackage' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.'

I tried to render it to save it to the disk using the following code:

  string deviceInfo = "<DeviceInfo>" +
      "  <OutputFormat>PDF</OutputFormat>" +
      "  <PageWidth>8.27in</PageWidth>" +
      "  <PageHeight>11.69in</PageHeight>" +
      "  <MarginTop>0.25in</MarginTop>" +
      "  <MarginLeft>0.4in</MarginLeft>" +
      "  <MarginRight>0in</MarginRight>" +
      "  <MarginBottom>0.25in</MarginBottom>" +
      "  <EmbedFonts>None</EmbedFonts>" +
      "</DeviceInfo>";
            string mimeType;
            string encoding;
            string fileNameExtension;
            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes = src.LocalReport.Render("PDF", deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
            //   byte[] Bytes = src.LocalReport.Render(format: "PDF", deviceInfo: "");
            if (Directory.Exists(Directory.GetParent(savePath).FullName) == false)
                Directory.CreateDirectory(Directory.GetParent(savePath).FullName);
            using (FileStream stream = new FileStream(savePath, FileMode.Create))
            {
                stream.Write(renderedBytes, 0, renderedBytes.Length);
            }

and then open it in a new tab, it shows as follows: enter image description here

The weird issue is that the downloaded file is shown correctly.

enter image description here

Hasan Shouman
  • 2,162
  • 1
  • 20
  • 26

1 Answers1

0

This could be due to many reasons. It could be a missing font, so try to use standard fonts only. Please check the below link which addressed the exception that you are getting and provided a solution for many different reasons. Rdlc Report in MVC project - Managed Debugging Assistant 'PInvokeStackImbalance'

Enlighten_me
  • 56
  • 1
  • 5