.Rdlc Report in MVC project - Managed Debugging Assistant 'PInvokeStackImbalance'
Asked Answered
R

8

15

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);
        }
Raze answered 6/8, 2019 at 21:44 Comment(0)
J
10

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.

Jun answered 20/10, 2019 at 20:57 Comment(3)
Thanks so much, It helped a lot after finding many solutions but not working...Nonperishable
This is not real answer for this subject please see this link "c-sharpcode.com/thread/…"Monsour
Is more simple, just change extension from .rdlc to .rdlSurvival
E
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
Epiphyte answered 4/2, 2020 at 2:7 Comment(2)
Thx! This solution works for me :) (VS Professional 2019 Version 16.4.4 + Microsoft.ReportingServices.ReportViewerControl.WebForms.150.1400.0)Coppery
Your solution works perfect for localhost. Any idea how to resolve this issue in Published Web App?Boothe
A
12

this has worked for me (keeping settings):

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

byte[] bytes = rdlc.Render("PDF", deviceInfo);
Acutance answered 11/2, 2021 at 14:8 Comment(3)
Yes, this no longer generates the error in Visual Studio, but currently Firefox depends on embedded fonts to function properly: wiki.mozilla.org/PDF.js/fontsAbeu
This worked for me, however, I also had to remove my Font (Replacing with "Arial") to create meaningful output.Issus
This also makes the resulting PDF much smaller.Cassis
J
10

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.

Jun answered 20/10, 2019 at 20:57 Comment(3)
Thanks so much, It helped a lot after finding many solutions but not working...Nonperishable
This is not real answer for this subject please see this link "c-sharpcode.com/thread/…"Monsour
Is more simple, just change extension from .rdlc to .rdlSurvival
D
3

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.

Dandridge answered 14/8, 2019 at 18:17 Comment(0)
U
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.

Urbana answered 26/3, 2020 at 5:22 Comment(0)
P
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" %>

Pteryla answered 1/10, 2019 at 13:53 Comment(0)
M
0

Please see this link rdlc prblem

It should be because of embedFonts in Pdf rdlc file

Monsour answered 18/11, 2020 at 8:26 Comment(0)
C
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.

Covalence answered 17/8, 2021 at 17:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.