用心计较般般错 安心自守事事宽

cgl 坚持、努力终有所获
  新随笔  :: 管理

开发环境:VS2008

报表:微软的rdlc

代码时,运行正常。制作安装包后,显示报表出错,出错类型为

 An error occurred during local report processing.Failed to load expression host assembly.Details:Requestfor the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

解决办法:在报表预览窗体,增加代码

            reportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(Assembly.GetExecutingAssembly().Evidence);
            reportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

 编译后,重新打包,运行正常。

网上说,如果开发环境为VS2010

那么需要增加代码:

var reportInstance = new LocalReport();
reportInstance.SetBasePermissionsForSandboxAppDomain(new PermissionSet(PermissionState.Unrestricted));

var permissionSet =newPermissionSet(PermissionState.None);
var flags =SecurityPermissionFlag.Execution|SecurityPermissionFlag.ControlPrincipal;
var permission =newSecurityPermission(flags); permissionSet.AddPermission(permission);
ReportViewer.LocalReport.SetBasePermissionsForSandboxAppDomain(permissionSet);

具体是否能行,没有试验。