Search code examples
c#asp.net-core.net-coreblazorrdlc

System.Security.Policy.Evidence.AddHostEvidence: type argument 'System.Security.Policy.Zone' violates the constraint of type parameter 'T'


I am trying to create rdlc report in blazor server project with .NET6, followed this blog guide which was layed out perfectly but rendering the report I was stuck with this error.

System.Security.Policy.Evidence.AddHostEvidence: type argument 'System.Security.Policy.Zone' violates the constraint of type parameter 'T'.'

this error occur when executing LocalReport report = new LocalReport(pathToRdlc);

i have search but nothing that helps. the error was reported on github some days back but no solution yet.

here is a sample project on github using same guide above.


Solution

  • I found this nuget package Microsoft.ReportViewer.NETCore and the Github repository as my alternative solution. its almost same implementation as detailed in this blog here but the get method implementation is as below for the nuget package. it save me from the error above, hope it helps you also.

     
     string reportName="TestReport"; 
     string reportPath =Path.Combine(webHostEnvironment.ContentRootPath,"ReportFiles", "SampleReport.rdlc"); //or webHostEnvironment.WebRootPath if your report is in wwwroot folder
    
     Stream reportDefinition; // your RDLC from file or resource
     //IEnumerable dataSource; // your datasource for the report
     using var fs = new FileStream(reportPath, FileMode.Open);
     reportDefinition = fs;
     LocalReport report = new LocalReport();
     report.LoadReportDefinition(reportDefinition);
     report.DataSources.Add(new ReportDataSource("source", dataSource));
     report.SetParameters(new[] { new ReportParameter("parameter1", "RDLC Sample Report ") });
     byte[] pdf = report.Render("PDF");
     fs.Dispose();
    
     return File(pdf, "application/pdf", reportName + ".pdf");