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

我即将完成并运行我的上一份报告。我在其他报告中没有遇到过这个问题。我正在尝试根据数据库记录创建报告。当我通过 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;

        }


忽然笑
浏览 156回答 6
6回答

慕哥6287543

我正在运行 Microsoft.ReportingServices.ReportViewerControl.WebForms 150.1400.0 并遇到同样的问题。强制iisexpress以64位运行即可解决此问题,步骤:工具选项项目及解决方案Web 项目并选中该选项对网站和项目使用 64 位版本的 IIS Express

猛跑小猪

PInvokeStackImbalance更多的是一个“调试助手”而不是一个例外。所以...就我而言,由于它并没有阻止呈现报告,因此我只是在调试项目时禁用了此异常。

手掌心

这对我有用(保留设置):var deviceInfo = @"<DeviceInfo>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <EmbedFonts>None</EmbedFonts>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</DeviceInfo>";byte[] bytes = rdlc.Render("PDF", deviceInfo);

杨魅力

我在仅调试时尝试将 RDLC 导出为 PDF 时遇到了此错误。Excel 和 Word 没有出现任何问题。它似乎是在几个月前我们从 ReportViewer.WinForms v14 升级到 v15 时开始的,但我们没有注意到,因为项目编译后就不会出现该错误,这证实了 @marcusgambit 提到的“调试异常” 。@brosolomon 和 @srivaishnavgandhe 关于字体的建议似乎也正确 - Arial 和 Times New Roman 渲染良好,而其余的则导致错误 - 我测试了 Calibri、Cambria、Verdana、Wingdings、Tahoma、Segoe。报告内容和数据似乎没有什么区别 - RDLC 中似乎存在除 Arial 或 Times New Roman 以外的任何字体的标签,这似乎导致了问题。

MMTTMM

我的报告也有同样的问题。确保您的报告没有不同的字体。我将报告更改为通篇使用 Arial 字体,错误已解决。

万千封印

有趣的是,我只在 Microsoft.ReportViewer.WebForms Version=15.0.0.0 中遇到过这种情况,以前的版本没有任何问题。什么有效:我以@Srivaishnav Gandhe 的身份做了。我混合了 Cambria 和 Ariel 字体。我把所有的 Cambria 都改成 Ariel 了,万岁 - 一切都成功了。还要小心,如果您在定义中设置了区域性并且报告上的日期格式与指定的区域性不同,则可能会发生这种情况。因此,将文化设置为中性是安全的:<%@&nbsp;Register&nbsp;assembly="Microsoft.ReportViewer.WebForms,&nbsp;Version=15.0.0.0,&nbsp;Culture=neutral,&nbsp;PublicKeyToken=89845dcd8080cc91"&nbsp;namespace="Microsoft.Reporting.WebForms"&nbsp;tagprefix="rsweb"&nbsp;%>
打开App,查看更多内容
随时随地看视频慕课网APP