首页 > 解决方案 > Azure 函数中的 Microsoft 报告 LocalReport:ReportProcessingException

问题描述

我创建了一个基本的Azure Function (.NET),我有一个生成LocalReport(基于 WinForms)的基本项目。这适用于 ASP.NET MVC 应用程序和单元测试,但不适用于 Azure 函数。

不完全是这样,但你得到了这个想法:

[FunctionName("Report")]
public static async Task<HttpResponseMessage> Report([HttpTrigger(AuthorizationLevel.Function, "POST", Route = "Report")]HttpRequestMessage req, ILogger log)
{
    Microsoft.Reporting.WinForms.LocalReport lr = new Microsoft.Reporting.WinForms.LocalReport();
    lr.ReportPath = "Sales.rdlc";
    lr.DataSources.Add(new ReportDataSource("Sales", GetSalesData()));

    // this line fails:
    var bytes = lr.Render("PDF", null, out mimeType, out encoding, out streamids, out warnings);

    response.Content = new ByteArrayContent(bytes);
    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

    return await Task.FromResult(response);
}

执行时lr.Render("PDF", ...),会出现以下错误:

Microsoft.Reporting.WinForms.LocalProcessingException
  HResult=0x80131500
  Message=An error occurred during local report processing.
  Source=Microsoft.ReportViewer.WinForms
  StackTrace:
   at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
   at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
   at Microsoft.Reporting.WinForms.LocalReport.Render(String format, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
   at Microsoft.Reporting.WinForms.Report.Render(String format, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)

Inner Exception 1:
ReportProcessingException: Failed to load expression host assembly. Details: Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies.

我真的看不出丢失的程序集是什么,但我的bin文件夹中有很多相关的程序集,包括:

这可能与“沙盒”问题有关吗?如果是,为什么此错误消息如此具有误导性?

有人在 Azure Functions 中运行 Microsoft 本地报告吗?

标签: azure-functionsms-reports

解决方案



推荐阅读