Asp.net core 如何为LocalReport设置“EnableExternalImages=true”

Asp.net core 如何为LocalReport设置“EnableExternalImages=true”,asp.net-core,rdlc,reporting-services-2016,Asp.net Core,Rdlc,Reporting Services 2016,我正在使用报告包-AspNetCore.reporting-2.1.0。我想打印带有外部图像的RDLC报告。在呈现为pdf时发生错误 An error occurred during local report processing.;Report 'Payslip' contains external images. The EnableExternalImages property has not been set for this report. 呈现我的部分代码: string repo

我正在使用报告包-AspNetCore.reporting-2.1.0。我想打印带有外部图像的RDLC报告。在呈现为pdf时发生错误

An error occurred during local report processing.;Report 'Payslip' contains external images. The EnableExternalImages property has not been set for this report.
呈现我的部分代码:

string reportFileName = "Payslip.rdlc";
if (paySlip.IsHourlySalary)
    reportFileName = "Payslip.rdlc";
else
{
    reportFileName = "PaySlipForAnnual.rdlc";
}
string ReportPath;
if (_webHostEnvironment != null)
    ReportPath = Path.Combine(_webHostEnvironment.ContentRootPath + "\\TMReports", reportFileName);
else
{
    ReportPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "/TMReports", reportFileName);
}
LocalReport localReport = new LocalReport(ReportPath);

message += " Before localReport.SetParameters(param);";
message += " Before localReport.DataSources.Add(cd);";
localReport.AddDataSource("dsPaySlip", dtPaySlip); // Add  datasource here    

message += " Before  byte[] bytes = localReport.Render(";
var result = localReport.Execute(RenderType.Pdf, 1, reportParams, mimeType);
               
return result.MainStream;

在渲染之前运行此命令

localReport.EnableExternalImages = true;
编辑:

您使用的开源库似乎没有公开所需的变量或方法

但是这些方法存在于密封类的私有变量中。

但是你仍然可以通过反射改变它的值

这并不漂亮,但它能完成任务

AspNetCore.Reporting.LocalReport rpt = new AspNetCore.Reporting.LocalReport(yourReportPath);
BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
FieldInfo field = rpt.GetType().GetField("localReport", bindFlags);
object rptObj = field.GetValue(rpt);
Type type = rptObj.GetType();
PropertyInfo pi = type.GetProperty("EnableExternalImages");
pi.SetValue(rptObj, true, null);

无法在asp.net core 5中设置。旧的asp.net reporting services也可以。我的问题是。但是该方法似乎仍然可以公开访问,您可能需要通过扩展AspNetCore.Reporting.LocalReport来创建自己的LocalReport类。如果您需要示例代码,请给我时间。@NandanKumarDas更新后的答案适合您吗?