MVC 项目中的 .Rdlc 报告 - 托管调试助手“PInvokeStackImbalance”

Big*_*ear 10 c# asp.net-mvc rdlc reporting-services

我非常接近完成我的上一份报告并运行。我在任何其他报告中都没有遇到过这个问题。我正在尝试根据数据库记录创建报告。当我通过 LocalReport 创建报告并为报告创建参数时,我收到错误消息“托管调试助手‘PInvokeStackImbalance’:‘调用 PInvoke 函数‘Microsoft.ReportViewer.Common!Microsoft.ReportingServices.Rendering.ImageRenderer。 FontPackage::CreateFontPackage' 使堆栈不平衡。这可能是因为托管 PInvoke 签名与非托管目标签名不匹配。检查 PInvoke 签名的调用约定和参数是否与目标非托管签名匹配。这是我的 MVC 项目的 .rdlc 报告。记录是正确的并且值被插入但是当我去显示它/创建它时报告错误。在 '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);
        }
Run Code Online (Sandbox Code Playgroud)

小智 12

这对我有用(保留设置):

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

byte[] bytes = rdlc.Render("PDF", deviceInfo);
Run Code Online (Sandbox Code Playgroud)

  • 是的,这不再在 Visual Studio 中生成错误,但目前 Firefox 依赖嵌入字体才能正常运行:https://wiki.mozilla.org/PDF.js/fonts (2认同)

cyu*_*yuz 11

我正在运行 Microsoft.ReportingServices.ReportViewerControl.WebForms 150.1400.0 并遇到同样的问题。

强制iis express运行64位就可以解决这个问题,步骤:

  • 工具
  • 选项
  • 项目和解决方案
  • Web 项目并选中该选项
  • 将 64 位版本的 IIS Express 用于网站和项目


小智 8

根据这个答案,PInvokeStackImbalance 更像是一个“调试助手”,而不是一个例外。所以...

就我而言,由于它不会阻止呈现报告,因此我只是在调试我的项目时禁用了此异常(请参阅告诉调试器继续处理用户未处理的异常)。这对我有用。