Reporting Services: Use a Custom Assembly with a Local (RDLC) Report

I am developing a report that will be used in local mode (RDLC file) in a Winform application. I have a custom assembly with a static class that has some functions that I want to use inside the report (as expressions).

I found all kinds of help for this with RDL reports, but I ran into a permission problem with my RDLC report.

I get the following error at runtime: "The report refers to a code module (my module), which is not a reliable assembly."

I know this is some kind of code security issue, but I'm not sure what to do to fix it. The documentation I saw on the Internet is for RDL reporting, and it instructs me to edit the SQL Server-specific policy file. I use RDLC, so the sql server is not involved. What do I need to do to get the appropriate permissions?

+5
source share
3 answers

Try using the AddTrustedCodeModuleInCurrentAppDomain method. ReportViewer.LocalReport property (reportViewer.LocalReport.AddTrustedCodeModuleInCurrentAppDomain ("your assembly")).

Also make sure that you use the AllowPartiallyTrustedCallers attribute with your assembly ([assembly: AllowPartiallyTrustedCallers]).

+7
source

The AddTrustedCodeModuleInCurrentAppDomain method has been deprecated for .Net 4.0. Visual Studio 2010 disables the call to this method. But there is an AddFullTrustModuleInSandboxAppDomain method in the LocalReport property of the ReportViewer class (reportViewer.LocalReport.AddFullTrustModuleInSandboxAppDomain (myAssemblyStrongName)). This requires a strong build name. My application works fine with Visual Studio, but I get the error message "Report refers to a code module (my module), which is not a reliable assembly" when I manually run an exe file from the "bin" folder. What could it be?

+3
source

The @StefanHa comment gives the answer, in case the blog post disappears here the code that worked for me:

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)); 

I also needed to set PermissionState.Unrestricted instead of PermissionState.None. In my example, I downloaded System.Web + System.Drawing and so I only needed to SetBasePermissionsForSandboxAppDomain .

0
source

Source: https://habr.com/ru/post/1304938/


All Articles