【问题标题】:System.Security.Policy.Evidence.AddHostEvidence: type argument 'System.Security.Policy.Zone' violates the constraint of type parameter 'T'System.Security.Policy.Evidence.AddHostEvidence:类型参数\'System.Security.Policy.Zone\'违反了类型参数\'T\'的约束
【发布时间】:2022-11-17 06:23:29
【问题描述】:

我正在尝试使用 .NET6 在 blazor 服务器项目中创建 rdlc 报告,然后是 this blog guide,它的布局非常完美,但呈现报告时我遇到了这个错误。

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

执行LocalReport report = new LocalReport(pathToRdlc);时出现此错误

我有搜索但没有任何帮助。几天前错误是reported on github,但还没有解决方案。

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

【问题讨论】:

    标签: c# asp.net-core .net-core blazor rdlc


    【解决方案1】:

    我发现这个 nuget 包 Microsoft.ReportViewer.NETCoreGithub repository 作为我的替代解决方案。它的实现与详细的 in this blog here 几乎相同 但是对于 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");
    

    【讨论】:

    • 谢谢!您的解决方案是唯一适用于 Blazor (net 6) 的解决方案。还重复使用相同的代码!
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2016-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-30
        • 1970-01-01
        • 2017-01-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多