14

I am so close to getting my last report up and running. I have not had this problem with any other reports. I am trying to create a report based off a database record. When I go to create the report by LocalReport and creating the parameters for the report I get the error message ‘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.' This is a .rdlc report for my MVC project. The record is correct and the values get inserted but when I go to display it /create it the report errors out. On the line ‘renderedBytes = localReport.Render(

/* TRACKER_TEST Database Connection ~ Debugging & Testing */
            TRACKER_TESTDataSet dataSet = new TRACKER_TESTDataSet();
            TRACKER_TESTDataSetTableAdapters.Service_Report_FieldsTableAdapter adapter = new TRACKER_TESTDataSetTableAdapters.Service_Report_FieldsTableAdapter();
            LocalReport localReport = new LocalReport();
            localReport.ReportPath = Server.MapPath("~/ReportForms/VirtualService2.rdlc");
            List<TRACKER_TESTDataSet.Service_Report_FieldsRow> report = new List<TRACKER_TESTDataSet.Service_Report_FieldsRow>();
            foreach(var row in list)
            {
                report.Add(adapter.GetDataBy(row.SN1, row.SN2).First());
            }
            ReportDataSource rds = new ReportDataSource("Service_Data", report);
            localReport.DataSources.Add(rds);


            // command specifies whether its a PDF EXCEL WORD IMAGE doc
            string reportType = command;
            string mimeType, encoding, fileNameExtension;

            string deviceInfo =
                "<DeviceInfo>" +
                "   <OutputFormat>" + command + "</OutputFormat>" +
                "   <PageWidth>8.5in</PageWidth>" +
                "   <PageHeight>11in</PageHeight>" +
                "   <MarginTop>0.5in</MarginTop>" +
                "   <MarginLeft>0.3in</MarginLeft>" +
                "   <MarginRight>0.3in</MarginRight>" +
                "   <MarginBottom>0.5</MarginBottom>" +
                "</DeviceInfo>";

            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes;

            renderedBytes = localReport.Render(
                reportType,
                deviceInfo,
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);

            return File(renderedBytes, mimeType);
        }
Bigbear
  • 489
  • 2
  • 5
  • 21

8 Answers8

15

I'm running Microsoft.ReportingServices.ReportViewerControl.WebForms 150.1400.0 with same problem.

Force iis express to run with 64 bit will solve this problem, steps:

  • Tools
  • Options
  • Project and Solutions
  • Web Projects and check the option
  • Use the 64 bit version of IIS Express for web sites and projects
cyuz
  • 151
  • 1
  • 4
11

According to this answer, PInvokeStackImbalance is more of a "debugging assistant" than an exception. So...

In my case, as it did not prevent the report from being rendered, I just disabled this exception when debugging my project (see Tell the debugger to continue on user-unhandled exceptions). This did the trick for me.

Marcus Gambit
  • 180
  • 1
  • 9
11

this has worked for me (keeping settings):

var deviceInfo = @"<DeviceInfo>
                    <EmbedFonts>None</EmbedFonts>
                   </DeviceInfo>";

byte[] bytes = rdlc.Render("PDF", deviceInfo);
  • 2
    Yes, this no longer generates the error in Visual Studio, but currently Firefox depends on embedded fonts to function properly: https://wiki.mozilla.org/PDF.js/fonts – Jedaias Rodrigues Jun 17 '21 at 13:58
  • This worked for me, however, I also had to remove my Font (Replacing with "Arial") to create meaningful output. – Marcel Mar 31 '22 at 08:36
3

I bumped into this error when trying to export a RDLC to PDF while debugging only. Excel & Word gave no issues.

It appears to have started when we upgraded from ReportViewer.WinForms v14 to v15 some months back but we didn't notice because the error doesn't occur once the project is compiled, confirming what @marcusgambit mentioned about it being a "debugging exception".

I used @cyuz's suggestion in our WinForms project - in the project Compile tab I un-ticked the "Prefer 32-bit" and that fixed the issue.

@brosolomon's & @srivaishnavgandhe's suggestion about fonts appears correct too - Arial & Times New Roman render fine while the rest cause an error - I tested Calibri, Cambria, Verdana, Wingdings, Tahoma, Segoe.

The report contents and data appear to make no difference - it seems the presence of a tag in the RDLC with any font other than Arial or Times New Roman that appears to cause the issue.

If you are interested this MS article discusses the rendering of SSRS to PDF and how SSRS will attempt to embed a font in a PDF but only if very specific conditions are met...I'm surmising this is where the failure is occurring.

AndrewD
  • 1,083
  • 9
  • 15
2

I had the same problem with my report. Make sure your report doesn't have different fonts. I changed my report to have Arial font throughout and the error was resolved.

1

Interestingly, I only experienced this with Microsoft.ReportViewer.WebForms Version=15.0.0.0 I had no issues with previous versions. And what worked: I did as @Srivaishnav Gandhe. I had a mix of Cambria and Ariel fonts. I changed all Cambria to Ariel and hooray - all worked. Be careful also, it may happen if you have set a culture on your definition and have got date on your report formatted differently from the culture specified. It is therefore safe to have a culture set to neutral:


<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

0

Please see this link rdlc prblem

It should be because of embedFonts in Pdf rdlc file

keivan kashani
  • 1,263
  • 14
  • 15
0

in your rdlc report, there are more than 1 font type. that's cause the problem. use ONLY 1 font type, the problem will gone.