Cannot Serialize the Sessions State
Environment
Product | Progress® Telerik® Reporting |
Version | Q2 2012 and later |
Report Viewers | Legacy ASP.NET WebForms Viewer |
The described scenario and suggested solution relate to the legacy ASP.NET WebForms ReportViewer. It is recommended that you migrate to the HTML5 ReportViewer.
Description
I am unable to serialize the session state when working with Telerik Reporting.
Cause
In the StateServer
and SQLServer
modes, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef
objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in the Custom
mode.
Solution
This exception might occur if you try to use objects which do not implement ISerializable
for a Report or Data Item data source. For example, if this is an IList
, you can try using a List
instead as shown in the cars Reporting demo.
You can also use the NeedDataSource
event of the report and assign the data source to the "processing report", thus avoiding any need for serialization or deserialization.
Another approach is to use a DataSet
or DataTable
:
DataTable dt = new DataTable();
DataColumn col = new DataColumn("ColumnName", typeof(string));
//....
dt.Columns.Add(col);
foreach (object Item in MyIList)
{
DataRow row = dt.NewRow();
row["ColumnName"] = Item;
//.....
dt.Rows.Add(row);
}