MVC 项目中的 .Rdlc 报告 - 托管调试助手 'PInvokeStackImbalance'
.Rdlc Report in MVC project - Managed Debugging Assistant 'PInvokeStackImbalance'
我快要完成上一份报告了 运行。我在任何其他报告中都没有遇到过这个问题。我正在尝试根据数据库记录创建报告。当我通过 LocalReport 创建报告并为报告创建参数时,我收到错误消息‘Managed Debugging Assistant '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);
}
我的报告也有同样的问题。确保您的报告没有不同的字体。我将我的报告更改为始终使用 Arial 字体,错误已解决。
有趣的是,我只在 Microsoft.ReportViewer.WebForms Version=15.0.0.0 时遇到过这种情况
我对以前的版本没有任何问题。什么起作用了:我做了@Srivaishnav Gandhe。
我混合使用了 Cambria 和 Ariel 字体。我将所有 Cambria 更改为 Ariel 和万岁 - 一切正常。
还要小心,如果您在定义中设置了一种文化,并且报告中的日期格式与指定的文化不同,则可能会发生这种情况。因此,将文化设置为中性是安全的:
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
根据此 answer,PInvokeStackImbalance 与其说是异常,不如说是 "debugging assistant"。所以...
在我的例子中,由于它没有阻止报告的呈现,我只是在调试我的项目时禁用了这个异常(参见Tell the debugger to continue on user-unhandled exceptions)。这对我有用。
我 运行宁 Microsoft.ReportingServices.ReportViewerControl.WebForms 150.1400.0 遇到同样的问题。
用 64 位强制 iis express 到 运行 将解决这个问题,步骤:
- 工具
- 选项
- 项目和解决方案
- Web 项目并勾选选项
- 为网站和项目使用 64 位版本的 IIS Express
我在仅调试时尝试将 RDLC 导出为 PDF 时遇到了这个错误。 Excel & Word 没有给出任何问题。
当我们几个月前从 ReportViewer.WinForms v14 升级到 v15 时,它似乎已经开始,但我们没有注意到,因为项目编译后错误不会发生,确认@marcusgambit 提到的内容它是 "debugging exception".
我在我们的 WinForms 项目中使用了@cyuz 的建议 - 在项目编译选项卡中我取消勾选 "Prefer 32-bit" 并解决了问题。
@brosolomon 和@srivaishnavgandhe 关于字体的建议似乎也正确 - Arial 和 Times New Roman 渲染良好,而其余字体会导致错误 - 我测试了 Calibri、Cambria、Verdana、Wingdings、Tahoma、Segoe。
报告内容和数据似乎没有区别 - 似乎 RDLC 中存在的标签使用 Arial 或 Times New Roman 以外的任何字体似乎会导致问题。
如果您有兴趣 this MS article 讨论将 SSRS 呈现为 PDF 以及 SSRS 将如何尝试在 PDF 中嵌入字体,但前提是满足非常特定的条件...我推测这是发生故障的地方。
请看这个linkrdlc prblem
应该是因为pdf rdlc文件中的embedFonts
这对我有用(保持设置):
var deviceInfo = @"<DeviceInfo>
<EmbedFonts>None</EmbedFonts>
</DeviceInfo>";
byte[] bytes = rdlc.Render("PDF", deviceInfo);
在您的 rdlc 报告中,有超过 1 种字体类型。这就是问题所在。只使用一种字体类型,问题就会消失。
我快要完成上一份报告了 运行。我在任何其他报告中都没有遇到过这个问题。我正在尝试根据数据库记录创建报告。当我通过 LocalReport 创建报告并为报告创建参数时,我收到错误消息‘Managed Debugging Assistant '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);
}
我的报告也有同样的问题。确保您的报告没有不同的字体。我将我的报告更改为始终使用 Arial 字体,错误已解决。
有趣的是,我只在 Microsoft.ReportViewer.WebForms Version=15.0.0.0 时遇到过这种情况 我对以前的版本没有任何问题。什么起作用了:我做了@Srivaishnav Gandhe。 我混合使用了 Cambria 和 Ariel 字体。我将所有 Cambria 更改为 Ariel 和万岁 - 一切正常。 还要小心,如果您在定义中设置了一种文化,并且报告中的日期格式与指定的文化不同,则可能会发生这种情况。因此,将文化设置为中性是安全的:
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
根据此 answer,PInvokeStackImbalance 与其说是异常,不如说是 "debugging assistant"。所以...
在我的例子中,由于它没有阻止报告的呈现,我只是在调试我的项目时禁用了这个异常(参见Tell the debugger to continue on user-unhandled exceptions)。这对我有用。
我 运行宁 Microsoft.ReportingServices.ReportViewerControl.WebForms 150.1400.0 遇到同样的问题。
用 64 位强制 iis express 到 运行 将解决这个问题,步骤:
- 工具
- 选项
- 项目和解决方案
- Web 项目并勾选选项
- 为网站和项目使用 64 位版本的 IIS Express
我在仅调试时尝试将 RDLC 导出为 PDF 时遇到了这个错误。 Excel & Word 没有给出任何问题。
当我们几个月前从 ReportViewer.WinForms v14 升级到 v15 时,它似乎已经开始,但我们没有注意到,因为项目编译后错误不会发生,确认@marcusgambit 提到的内容它是 "debugging exception".
我在我们的 WinForms 项目中使用了@cyuz 的建议 - 在项目编译选项卡中我取消勾选 "Prefer 32-bit" 并解决了问题。
@brosolomon 和@srivaishnavgandhe 关于字体的建议似乎也正确 - Arial 和 Times New Roman 渲染良好,而其余字体会导致错误 - 我测试了 Calibri、Cambria、Verdana、Wingdings、Tahoma、Segoe。
报告内容和数据似乎没有区别 - 似乎 RDLC 中存在的标签使用 Arial 或 Times New Roman 以外的任何字体似乎会导致问题。
如果您有兴趣 this MS article 讨论将 SSRS 呈现为 PDF 以及 SSRS 将如何尝试在 PDF 中嵌入字体,但前提是满足非常特定的条件...我推测这是发生故障的地方。
请看这个linkrdlc prblem
应该是因为pdf rdlc文件中的embedFonts
这对我有用(保持设置):
var deviceInfo = @"<DeviceInfo>
<EmbedFonts>None</EmbedFonts>
</DeviceInfo>";
byte[] bytes = rdlc.Render("PDF", deviceInfo);
在您的 rdlc 报告中,有超过 1 种字体类型。这就是问题所在。只使用一种字体类型,问题就会消失。