System.Security.Policy.Evidence.AddHostEvidence:类型参数“System.Security.Policy.Zone”违反了类型参数“T”的约束

问题描述 投票:0回答:5

我正在尝试使用 .NET6 在 blazor 服务器项目中创建 rdlc 报告,遵循 this 博客指南 布局完美但呈现报告时我遇到了这个错误。

System.Security.Policy.Evidence.AddHostEvidence:类型参数 'System.Security.Policy.Zone' 违反了类型参数 'T' 的约束。'

执行时出现此错误

LocalReport report = new LocalReport(pathToRdlc);

我有搜索但没有任何帮助。错误是 reported on github some days back but no solution yet.

这里是 github 上使用上述相同指南的示例项目。

c# asp.net-core .net-core blazor rdlc
5个回答
3
投票

我发现这个 nuget 包

Microsoft.ReportViewer.NETCore
Github 存储库 作为我的替代解决方案。它的实现与此处博客中的详细几乎相同 但是对于 nuget 包,get 方法的实现如下所示。它使我免于上述错误,希望对您也有帮助。

 
 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");

2
投票

系统.安全.权限

NuGet\Install-Package System.Security.Permissions -Version 7.0.0

我解决了添加上述Nuget包的问题。 完美的工作。现在没有错误了。


0
投票

对我来说,安装包“System.Security.Permissions”解决了这个问题。


0
投票
dotnet add package System.Security.Permissions --version 7.0.0

解决


-1
投票

我还使用了 AspNetCore.Reporting 包,在将我的解决方案更新到 .net 6 后遇到了同样的问题。 我更改为 ReportViewer.NETCore 并解决了问题。

© www.soinside.com 2019 - 2024. All rights reserved.