You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET Core 3.1中RDLC文件图表控件无法正常工作求助

修复ASP.NET Core 3.1中RDLC图表PDF渲染缺失问题

问题根源

RDLC的图表控件依赖Windows专属的System.Windows.Forms程序集,但ASP.NET Core默认不包含该组件,导致渲染图表时触发程序集找不到的错误,而表格等非图表元素不受影响。

解决方法

  1. 安装依赖NuGet包

    • 安装System.Windows.Forms和适配ASP.NET Core的RDLC报表包:
      Install-Package System.Windows.Forms -Version 4.7.0
      Install-Package AspNetCore.Reporting -Version 1.1.0
      
  2. 配置项目文件

    • 打开.csproj文件,确保以下引用已添加,避免发布时丢失依赖:
      <ItemGroup>
        <PackageReference Include="System.Windows.Forms" Version="4.7.0" />
        <PackageReference Include="AspNetCore.Reporting" Version="1.1.0" />
      </ItemGroup>
      
  3. 调整报表渲染代码

    • 使用AspNetCore.Reporting的LocalReport处理报表,确保依赖加载正常:
      var reportFilePath = Path.Combine(WebHostEnvironment.WebRootPath, "Reports", "YourReport.rdlc");
      var localReport = new LocalReport(reportFilePath);
      localReport.AddDataSource("ReportDataSet", yourDataCollection);
      
      var renderResult = localReport.Execute(RenderType.Pdf, 1, new Dictionary<string, string>());
      return File(renderResult.MainStream, "application/pdf", "GeneratedReport.pdf");
      
  4. 部署环境注意事项

    • 如果部署到Linux/macOS,由于System.Windows.Forms和GDI+依赖无法跨平台工作,图表仍会失效,建议部署到Windows服务器,或更换为支持跨平台的报表组件。

内容的提问来源于stack exchange,提问作者Anand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 12:55:03