0

My ASP.Net Core RDLC Report is working fine but tried to hide row when the field value is zero by right click the rdlc report row and then click Row Visibility. In the Row Visibility dialog box I selected Show Or Hide based on an Expression Under Change display options and used this expression

IIf(Fields!StudentAmt.Value=0,True,False) 

and got the following error.

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

I am using Reference of AspNetCore.Reporting for local Report

And this Second Error displayed as a result of this expression Format(Fields!OEndDate.Value, "MMM-yyyy")

IndexOutOfRangeException: Index was outside the bounds of the array.

My 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");
 } 
dausa
  • 101
  • 7

1 Answers1

1

Are you using AspNetCore.Reporting? Do not use any expressions, report will fail. This is limitation of this library.

If you wish to hide rows using the expression, I recommend you to use ReportViewerCore.NETCore.

Below is my test, you can refer to it:

public IActionResult Report()
{
    var test = _context.Table.ToList();
    var path = $"{_webHostEnvironment.WebRootPath}\\Reports\\Report2.rdlc";

    LocalReport report = new LocalReport();
    report.ReportPath= path;
            
    report.DataSources.Add(new ReportDataSource("DataSet1", test));
    report.SetParameters(new[] { new ReportParameter( "rdl", "Student Name" ) });
    byte[] pdf = report.Render("PDF");
    return File(pdf, "application/pdf");
}

Before using the expression:

enter image description here

After using the expression:

enter image description here

Output Result:

enter image description here

More details about ReportViewerCore.NETCore, you can refer to this link.

Your second error may just be a problem with data loading, you can refer to this link to solve it.

Chen
  • 4,499
  • 1
  • 2
  • 9
  • Thanks Chen your suggestion is Ok. but I try to Install `ReportViewerCore.NETCore` did not install. I don't know the problem for not install. Using ASP.Net 3.1 Community Version 2019. – dausa Dec 06 '22 at 09:30
  • During the installation, are there any error messages in the "`Error List`"? @dausa – Chen Dec 06 '22 at 09:37
  • Try to install multiple times, pay attention to whether there is an error log output. – Chen Dec 06 '22 at 09:38
  • Here is an error `Could not install package 'ReportViewerCore.NETCore 15.1.17'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.7.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.`. – dausa Dec 06 '22 at 09:41
  • Can you share your `.csproj` file? @dausa – Chen Dec 06 '22 at 09:45
  • For [.NET Core](https://www.nuget.org/packages/ReportViewerCore.NETCore) and [.NET Framework](https://www.nuget.org/packages/Microsoft.ReportViewer) is different. Please confirm it. – Chen Dec 06 '22 at 09:51
  • Here is .csproj ` netcoreapp3.1 ` – dausa Dec 06 '22 at 09:52
  • how to change TargetFramework and my project remain working – dausa Dec 06 '22 at 10:04