I can help.
The problem is that the ReportViewer control uses Session to store the current executable report. After you switch from reports, the element still remains and ultimately loses its "execution context" because the report server caches reports.
Therefore, before viewing a report, you should try to clear the session of these reports so that there are no cached reports in the session and the ReportViewer control may work correctly.
You will also find that sometimes when accessing Session.Keys.Count this error can occur, as is the case with the execution context.
Make sure you do this on the message page!
2 options:
if (!IsPostBack) { HttpContext.Current.Session.Clear(); ReportViewer1.ServerReport.ReportServerUrl = new Uri(ReportServerUrl, System.UriKind.Absolute); ReportViewer1.ServerReport.ReportPath = ReportPath; System.Collections.Generic.List<ReportParameter> parameters = new System.Collections.Generic.List<ReportParameter>(); .... ReportViewer1.ServerReport.SetParameters(parameters); ReportViewer1.ServerReport.Refresh(); }
or
for (int i = 0; i < HttpContext.Current.Session.Keys.Count; ) { if (HttpContext.Current.Session[i].ToString() == "Microsoft.Reporting.WebForms.ReportHierarchy") HttpContext.Current.Session.RemoveAt(i); else i++; }
source share