C# reporting services:将自定义程序集与本地(RDLC)报告一起使用
我正在设计一个将在Winform应用程序中以本地模式(RDLC文件)使用的报告。我有一个自定义程序集,它具有静态类,它具有一些函数,我想在报表内部使用(作为表达式) 我在RDL报告中找到了各种各样的帮助,但是我的RDLC报告遇到了权限问题 我在运行时遇到以下错误: 报表引用的代码模块(my模块)不是受信任的程序集 我知道这是某种代码安全性问题,但我不确定该如何解决它。我在网上看到的文档是针对RDL报告的,它指示我编辑特定于SQL Server的策略文件。我使用的是RDLC,因此不涉及sql server。我需要做什么才能获得适当的权限?尝试使用 (reportViewer.LocalReport.AddTrustedCodeModuleInCurrentAppDomain(“您的程序集”))C# reporting services:将自定义程序集与本地(RDLC)报告一起使用,c#,reporting-services,reporting,C#,Reporting Services,Reporting,我正在设计一个将在Winform应用程序中以本地模式(RDLC文件)使用的报告。我有一个自定义程序集,它具有静态类,它具有一些函数,我想在报表内部使用(作为表达式) 我在RDL报告中找到了各种各样的帮助,但是我的RDLC报告遇到了权限问题 我在运行时遇到以下错误: 报表引用的代码模块(my模块)不是受信任的程序集 我知道这是某种代码安全性问题,但我不确定该如何解决它。我在网上看到的文档是针对RDL报告的,它指示我编辑特定于SQL Server的策略文件。我使用的是RDLC,因此不涉及sql se
另外,请确保将属性用于程序集([assembly:AllowPartiallyTrustedCallers])。AddTrustedCodeModuleInCurrentAppDomain方法对于.Net 4.0已过时。Visual Studio 2010禁用此方法的调用。但是ReportViewer类(ReportViewer.LocalReport.AddFullTrustModuleInSandboxAppDomain(myAssemblyStrongName))的LocalReport属性中有一个方法。它需要程序集的强名称。我的应用程序在Visual Studio中运行良好,但当我从文件夹“bin”手动运行exe文件时,出现错误“报告引用了代码模块(我的模块),该模块不是受信任的程序集”。可能是什么?@StefanHa的评论提供了答案,如果博客帖子消失了,下面是对我有用的代码:
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
PermissionSet permissions = new PermissionSet(PermissionState.None);
permissions.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
rv.LocalReport.SetBasePermissionsForSandboxAppDomain(permissions);
Assembly asm = Assembly.Load("MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
AssemblyName asm_name = asm.GetName();
rv.LocalReport.AddFullTrustModuleInSandboxAppDomain(new StrongName(new StrongNamePublicKeyBlob(asm_name.GetPublicKeyToken()), asm_name.Name, asm_name.Version));
我还需要设置PermissionState.Unrestricted而不是PermissionState.None。在我的示例中,我正在加载System.Web+System.Drawing,因此我只需要最多
SetBasePermissionsForSandboxAppDomain
,这就是诀窍!我有AllowPartiallyTrustedCallers,但我错过了AddTrustedCodeModuleInCurrentAppDomain的调用。顺便说一句,该方法在.NET4.0中已被弃用,现在有了一种新的方法。谢谢你的帮助!