开发环境: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);
具体是否能行,没有试验。
作者:
cglnet
本文版权归cglNet和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.