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

10,032

Solution 1

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.

Solution 2

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

Solution 3

this has worked for me (keeping settings):

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

byte[] bytes = rdlc.Render("PDF", deviceInfo);

Solution 4

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.

Solution 5

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.

Share:
10,032
Bigbear
Author by

Bigbear

Experienced Software Developer with a demonstrated history of working in the Computer Software &amp; Hardware industry. Skilled in .Net C#, HTML5/CSS3/Bootstrap4, JavaScript/jQuery/PHP, Databases, Web Design, Java, Microsoft Office, and Adobe Suite.

Updated on July 06, 2022

Comments

  • Bigbear
    Bigbear almost 2 years

    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);
            }
    
  • claudiosfr
    claudiosfr over 4 years
    Thx! This solution works for me :) (VS Professional 2019 Version 16.4.4 + Microsoft.ReportingServices.ReportViewerControl.WebForms.150‌​.1400.0)
  • Prashant Manjule
    Prashant Manjule about 4 years
    Thanks so much, It helped a lot after finding many solutions but not working...
  • Alex
    Alex about 4 years
    Bingo! Thanks (y)
  • keivan kashani
    keivan kashani over 3 years
    This is not real answer for this subject please see this link "c-sharpcode.com/thread/…"
  • Jedaias Rodrigues
    Jedaias Rodrigues almost 3 years
    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/fonts
  • HardcoreGameDev
    HardcoreGameDev over 2 years
    Unlikely. Given the other answers and their upvotes.
  • Marcel
    Marcel about 2 years
    This worked for me, however, I also had to remove my Font (Replacing with "Arial") to create meaningful output.
  • Ruben
    Ruben about 2 years
    Is more simple, just change extension from .rdlc to .rdl