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

ASP.Net Core 3.1 RDLC报表表达式编译及格式化报错求助

ASP.Net Core RDLC报表表达式编译及格式化错误解决方案

问题详情

1. 行可见性表达式编译错误

设置报表行可见性为「基于表达式显示或隐藏」,使用表达式IIf(Fields!StudentAmt.Value=0,True,False)时,抛出异常:

ReportProcessingException: An unexpected error occurred while compiling expressions. Native compiler return value: ‘[BC30390] 'AspNetCore.ReportingServices.RdlExpressions.ExpressionHostObjectModel.DataRegionExprHost(Of TMemberType, TCellType).m_memberTreeHostsRemotable' is not accessible in this context because it is 'Friend'

2. 日期格式化数组越界错误

使用Format(Fields!OEndDate.Value, "MMM-yyyy")格式化日期时,抛出:

IndexOutOfRangeException: Index was outside the bounds of the array.

使用AspNetCore.Reporting库实现本地报表,Controller核心代码如下:

public IActionResult Report()
{
  string mimtype = "";
  int extension = 1;
  Dictionary<string, string> parameters = new Dictionary<string, string>
  {
     { "rpl", "Student Name" }
  };
   LocalReport localReport = new LocalReport(mypath);
   localReport.AddDataSource("DataSet1", mydatasource);
   var result = localReport.Execute(RenderType.Pdf, extension, parameters, mimtype);

  return File(result.MainStream, "application/pdf");
} 

解决方案

针对行可见性表达式错误

  • 降低库版本:将AspNetCore.Reporting降级到3.1.1或2.1.0版本,这些版本对RDLC表达式编译的兼容性更稳定
  • 简化表达式写法:直接使用布尔表达式替代IIf函数,将表达式改为Fields!StudentAmt.Value=0,RDLC会直接识别该布尔值作为显示/隐藏的判断依据

针对日期格式化错误

Format函数在该库环境中存在bug,推荐以下替代方案:

  • 使用FormatDateTime函数:FormatDateTime(Fields!OEndDate.Value, DateFormat.ShortMonthYear)
  • 使用原生字符串格式化:Fields!OEndDate.Value.ToString("MMM-yyyy"),若字段可能为空,可添加空值判断:IIf(IsNothing(Fields!OEndDate.Value), "", Fields!OEndDate.Value.ToString("MMM-yyyy"))

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 23:40:57