Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Microsoft Report Viewer: Request for the permission of type 'System.Security.Permissions.SecurityPermission' Failed

Problem Summary

I'm supporting an older ASP.NET intranet web application which is using the Microsoft.ReportViewer library.

When run, the report throws the following error:

An error has occurred during report processing.

The Sort expression for the grouping ‘list1_Details_Group’ contains an error:

Request for the permission of type: 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

All my research suggests that this problem arises from the application not having the necessary trust levels (all relevant stack overflow questions were solved by setting trust level to full), but my web config defines the trust level at full, so I'm completely lost as to why this error is occurring.

I can't show all of the web config for security reasons, but the majority of it can be found here: http://pastebin.com/GdJhHDhH Anything missing has been commented or stubbed.

Potentially Helpful Details

This problem arose after migrating the application from Forms Authentication to Windows Authentication. Not necessarily related, but hard to ignore the coincidence.

This problem is occurring across all my environments: Local, Dev and Prod (winding prod back to Forms Authentication makes this work).

The application is written in .Net 4, C#

The reporting code lives in a different assembly to the the web application, and the web application refers to the reporting assembly.

The web application successfully retrieves other data from the database in other areas of the application unrelated to reporting.

I'm at my wits end on this, any guidance would be great.

Update: Attempted Solutions

Tried removing list1_Details_Group. When this is done, another part of the report throws the same exception.

Tried using impersonation with Windows Authentication. The application continued to work in the same way, while throwing the same exception in the report.

Tried Strongly Naming all assemblies used within the application. No The application continued to work in the same way, while throwing the same exception in the report.

Tried using the "Classic" Managed pipeline in IIS.

like image 351
Jamie Butler Avatar asked Sep 22 '16 04:09

Jamie Butler


2 Answers

Ok, I know this is an old post. But I started having the exact same issue and could not find any solutions posted anywhere, so I'm posting my solution here.

ASP.NET 4.5, ReportViewer 11. Moving from Forms Authentication to Windows Authentication. Sorting in the report works fine in Forms Authentication, but I get a security/permission error with Windows Authentication.

I was able to reproduce the above both on the a Windows Server 2012 R2 as well as my local Windows 10 development environment (Visual Studio 2015).

What I found is that that I only get this issue when sorting across multiple columns with a SortExpression like the following:

=Fields!glp.Value & Fields!building_number.Value & Fields!room_number.Value

If I just do a simple sort on a field without a sort expression everything works fine.

I have Full Trust Set and all related properties in my Web.config—obviously, because it works with Forms Authentication.

Solution

To resolve this, set the permissions for the sandbox as follows:

rvReservations.ProcessingMode = ProcessingMode.Local;
LocalReport local_report = rvReservations.LocalReport;
local_report.ReportPath = "Reports\\rReservations.rdlc";
local_report.DataSources.Clear();

local_report.SetBasePermissionsForSandboxAppDomain(new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted));

Note: You will get the same behavior if you are passing parameters to your report; the same solution also applies.

like image 158
user1579692 Avatar answered Oct 23 '22 15:10

user1579692


A few issues may be happening.

The first and most obvious, take a look at the error, it says

The Sort expression for the grouping ‘list1_Details_Group’ contains an error

Let's address that first. Start by going to the Sorting property and find the associated group list1_Details_Group. If you've removed it and the issue is still present, then you'll have to look into the .rdl code and do a find for list1_Details_Group. If you find instances of it, it means it's still around. Clean those up.

Additional notes: The second thing you need to look into is other "variables" may be affecting your setup. It has been reported that this issue could be caused by a third=party plugin or DLL. Have you added any third-party DLLs that weren't part of the original environment that only came into play at the time of switching to Windows Authentication?

Hope this helped in any way to get you on the right track.

like image 2
megamaiku Avatar answered Oct 23 '22 17:10

megamaiku