ReportViewer 2010 fails to evaluate expressions

2019-03-16 11:28发布

问题:

My project is ASP.Net WebForms on 4.0 framework, using the ReportViewer 10, local RDLC reports rendered using Local processing mode.

My problem is that many of the expressions in my report are not evaluating. For example, I have a textbox in the footer of the report with the simple expression of =Globals!PageNumber - but when the report runs, i just get #Error in that field. I get a similar #Error just doing a ToString on one of my fields - =Fields!MyBooleanField.Value.ToString().

Also in my footer, =DateTime.Now DOES work, while =Globals!ExecutionTime does NOT work.

This makes no sense to me - it's as if I'm missing a reference or something. I have references in my project to both Microsoft.ReportViewer.Common (v10) and Microsoft.ReportViewer.WebForms (v10).

Anyone have any suggestions as to what I'm missing, or how I can get this resolved?

回答1:

I've seen three options:

Option 1: Elevate sandbox permissions

Expressions are compiled into a separate assembly and run in a sandbox with fewer permissions. Use this to increase the permissions given to the sandbox. There is probably a smaller permission set you can grant, we just haven't spent the time to figure this out. This will mean the report and any assemblies it references will have elevated permissions. This solution is working for us (MVC 3, .Net 4, VS2010, Microsoft.Reporting v10) though we haven't deployed to production yet.

localReport.SetBasePermissionsForSandboxAppDomain(
    AppDomain.CurrentDomain.PermissionSet.Copy());

Option 2: Build on .Net 3.5 Framework

Compile your project under .Net 3.5

Option 3: legacyCasModel

Add this to your web.config:

<system.web>
  <trust legacyCasModel="true" level="Full"/>
</system.web>

This prevents you from using dynamic variables (in some or all cases?). In particular, Asp.Net MVC 3 cannot be used because the ViewBag is dynamic.

More information

http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/be1a6149-a120-4e66-96f8-63f5c4d43c87

http://blogs.msdn.com/b/brianhartman/archive/2010/02/18/expression-evaluation-in-local-mode.aspx



回答2:

The issue is due to some CAS policy changes in framework 4.0. Please add the following line in the web.config:

<trust legacyCasModel="true" level="Full"/>

in the <system.web> section

Refer link below:

http://blogs.msdn.com/b/brianhartman/archive/2010/02/18/expression-evaluation-in-local-mode.aspx