Thursday, 9 July 2020

Unable to serialize the session state


This issue occurred in my case when I change my application session State mode "InProc" to "SQL Server". And I was used the SSRS Report in my application.

<sessionState mode="InProc"........../>

<sessionState mode="SQLServer"........../>

Solution 1:- Decorate your class with [Serializable] Attribute

Solution 2:- For SSRS Report => Create ReportServer Class

using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Net;
using System.Security.Principal;
 
[Serializable]
public sealed class ReportServer : IReportServerConnection2
{     private string _userName;     private string _password;     private string _domain;
      public ReportServer(string userName, string password, string domain)     {
        _userName = userName;
        _password = password;
        _domain = domain;
    }
 
    public ReportServer(NetworkCredential networkCredential)
    {
        _userName = networkCredential.UserName;
        _password = networkCredential.Password;
        _domain = networkCredential.Domain;
    }
 
        public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)     {
        authCookie = null;
        userName = null;
        password = null;
        authority = null;
        return false;     }
        public WindowsIdentity ImpersonationUser { get { return null; }}
 
    public ICredentials NetworkCredentials
    {
        get { return new NetworkCredential(_userName, _password, _domain); }
    }
      public Uri ReportServerUrl { get { return null; } }
        public int Timeout { get { return 60000; }}
        public IEnumerable<Cookie> Cookies { get { return null; }}
      public IEnumerable<string> Headers { get { return null; }}
}

=> .aspx Code

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="Microsoft.Reporting.WebForms" TagPrefix="asp" %>

<asp:ReportViewer ID="ReportViewer1" runat="server" Visible="False">
</asp:ReportViewer>

=> .cs Code

ReportParameter[] params = new ReportParameter[1];
params[0] = new ReportParameter("Parameter Name", "Parameter Value");
 
ReportViewer1.Visible = false;
ReportViewer1.Reset();
 
ReportViewer1.ServerReport.ReportServerCredentials = new ReportServer("Report Server User Id","Report Server Password", "");
 
//Or Use can use ReportServer class overloaded constructor
 
//ReportViewer1.ServerReport.ReportServerCredentials = new ReportServerConnection(new NetworkCredential("Report Server User Id", "Report Server Password", ""));
 
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl = new Uri("Report Server URL");
ReportViewer1.ServerReport.ReportPath = "Report Server Path";
//ReportViewer1.Height = 900;
if (params != null)
{
    ReportViewer1.ServerReport.SetParameters(params);
    ReportViewer1.ShowParameterPrompts = true;
}
ReportViewer1.Visible = true;
ReportViewer1.ServerReport.Refresh();

No comments:

Post a Comment