2010-03-23 114 views
4

我正在设计将在Winform应用程序中以本地模式(RDLC文件)使用的报告。我有一个静态类的自定义程序集,它具有一些我想在报表中使用的函数(作为表达式)。报告服务:使用具有本地(RDLC)报告的自定义程序集

我发现用RDL报告做这些的各种帮助,但我遇到了我的RDLC报告的权限问题。

我在运行时出现以下错误: “报告引用了代码模块(我的模块),它不是受信任的程序集”。

我知道这是某种代码安全问题,但我不知道该如何解决它。我在线看到的文档针对RDL报告,它指示我编辑SQL Server特定的策略文件。我正在使用RDLC,因此没有涉及到sql服务器。我需要做些什么来获得适当的权限?

回答

5

尝试使用AddTrustedCodeModuleInCurrentAppDomain方法的 ReportViewer.LocalReport Property(reportViewer.LocalReport.AddTrustedCodeModuleInCurrentAppDomain(“your assembly”))。

此外请确保您的程序集使用了AllowPartiallyTrustedCallers属性([assembly:AllowPartiallyTrustedCallers])。

+1

这就是诀窍!我有AllowPartiallyTrustedCallers,但我错过了对AddTrustedCodeModuleInCurrentAppDomain的调用。顺便说一句,该方法已被弃用。NET 4.0,并有一个新的方法来做到这一点。谢谢您的帮助! – JMarsch 2010-03-24 15:59:25

2

对于.Net 4.0,AddTrustedCodeModuleInCurrentAppDomain方法已过时。 Visual Studio 2010禁用此方法的调用。但ReportViewer类的LocalReport属性中有AddFullTrustModuleInSandboxAppDomain方法(reportViewer.LocalReport.AddFullTrustModuleInSandboxAppDomain(myAssemblyStrongName))。它需要组件的强名称。我的应用程序在Visual Studio中执行得很好,但是当我从文件夹“bin”手动运行exe文件时,出现错误“报告引用了代码模块(我的模块),这不是可信程序集”。它可能是什么?

+0

http://devcoma.blogspot.nl/2010_05_01_archive.html – StefanHa 2016-02-26 13:09:01