Error with Report Viewer when adding parameters for an add-in project for Revit

Error with Report Viewer when adding parameters for an add-in project for Revit

corinne.astori
Advocate Advocate
3,571 Views
5 Replies
Message 1 of 6

Error with Report Viewer when adding parameters for an add-in project for Revit

corinne.astori
Advocate
Advocate

Hello!

I started a project of an add-in for Revit which should take some parameters (values from Revit elements) and show them in a Report (a Report RDLC) and then be able to print the report. I developed the project in Visual Studio 2017 on .Net Framework 4.7.2 starting with the “Revit 2019 Addin” from The Building Coder. I added the NuGet Package Microsoft.ReportingServices.reportViewerControl.Winforms (and the package Microsft.SqlServer.Types that comes with it). I then added a Report.rdlc and a form with a report viewer on it. I first added a simple text to the report and tried to run the add-in in Revit 2019 and it worked fine (showing the report). I then added some parameters to the report and here start the problems L, the report shows an error :

“An error occurred during local report processing. Failed to load expression host assembly. Details: Impossible to load the file or the assembly ‘Microsoft.ReportViewer.Common, Version 15.0.0.0, Culture=neutral, PublicKey Token= 89845dcd8080cc91’…”

After searching around in the web, it seems that this is a problem with security policies related to ReportViewer. I also tried to add these three lines of code (which I found on a blog and were solving the problem by a couple of users) in the load method of the form that contains the ReportViewer:

this.reportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(System.Reflection.Assembly.GetExecutingAssembly().Evidence);

PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted);

this.reportViewer1.LocalReport.SetBasePermissionsForSandboxAppDomain(permissions);

 

But unsuccessfully… it still doesn’t work and now it is showing a message box with this error:

“Report execution in the current AppDomain requires Code Access Security policy, which is off by default in .NET 4.0 and later.  Enable legacy CAS policy or execute the report in the sandbox AppDomain”.

 

I have to add, that I’m not very experienced with programming and the Revit API, but I really would like this project to work….

Your help will be very much appreciated! THX

0 Likes
Accepted solutions (1)
3,572 Views
5 Replies
Replies (5)
Message 2 of 6

jesse.mom
Contributor
Contributor

I don't have a solution, but i ran in to the same problem today... Found a fix already?

 

Kind regards,

 

Jesse

0 Likes
Message 3 of 6

corinne.astori
Advocate
Advocate

Hi Jesse

Unfortunately I didn't find a solution. I ended up creating the report in form of a .docx file (using a word document as a template).

Regards

Corinne

0 Likes
Message 4 of 6

jesse.mom
Contributor
Contributor
Accepted solution

Hi Corinne,

 

I finally fixed the issue. I do not fully understand how it works, but it works. It does not have to do anything with the security issue or whatsoever.

 

The error that is displayed in the reportviewer control at runtime says that it cannot find Microsoft.ReportViewer.Common, Version 15.0.0.0. Even though the file is included in the nuget package and referenced in your visual studio project. Extensive research in the dark corners of the web showed me that it is looking for this file in the GAC (Global Assembly Cache), not in the folder where your addin resides. Indeed, when I looked in the GAC, there where versions of Microsoft.ReportViewer.Common but not 15.0.0.0. 

 

When I added this file (Microsoft.ReportViewer.Common.dll) and Microsoft.ReportViewer.ProcessingObjectModel.dll as downloaded from NuGet to the GAC it worked! See link below on how to do this. 

 

https://docs.microsoft.com/en-us/dotnet/framework/app-domains/how-to-install-an-assembly-into-the-ga... 

 

Now this fixes the problem on my machine, but not for other users of my tool. Therefore, you need to create an installer file, and make sure the installer file for your revit addin that additionally places the files in the gac of the target machine.  See links below on how to do that.

 

https://support.microsoft.com/en-us/help/324168/how-to-deploy-an-assembly-to-the-target-computer-glo...

 

https://stackoverflow.com/questions/44286704/create-setup-msi-installer-in-visual-studio-2017

 

Good luck!

0 Likes
Message 5 of 6

corinne.astori
Advocate
Advocate

Hi Jesse

 

Thank you very much for your effort and taking the time to let me know how to fix the issue. I'm going to try this procedure as soon as possible.

Cheers

Corinne

0 Likes
Message 6 of 6

c4rlos.dias
Observer
Observer

I solved the problem by copying the DLL files to the revit add in folder.

0 Likes