A call to PInvoke function Microsoft.ReportViewer.Common

  • 5.4K Views
  • Last Post 5 days ago
admin posted this 23 October 2019

This post shows you How to fix: Managed Debugging Assistant 'PInvokeStackImbalance' when using Microsoft.ReportViewer.Common in C# .NET.

Managed Debugging Assistant 'PInvokeStackImbalance' 

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.'

The problem occurs when using multiple font in RDLC report.

To fix Microsoft.ReportViewer.Common!Microsoft.ReportingServices.Rendering.ImageRenderer.FontPackage

You can add

<EmbedFonts>None</EmbedFonts>

to DeviceInfo as shown below.

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 = report.Render("PDF", deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
return File(renderedBytes, mimeType);
Order By: Standard | Newest | Votes
Paraglider posted this 05 December 2019

Thanks mate, you made my day!

jedarc posted this 5 days ago

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

Close