This is a migrated thread and some comments may be shown as answers.

Error during serialization or deserialization using the JSON JavaScriptSerializer - With Self Referencing RadGrid

4 Answers 357 Views
Grid
This is a migrated thread and some comments may be shown as answers.
venkatraman
Top achievements
Rank 1
venkatraman asked on 15 Oct 2008, 12:00 PM

I am trying to use the self-referencing hierarchy functionality of the grid but not working properly when we have huge data.

We are getting the error as follows,

 "Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property."

When i googgled,i got the following code snippet has to be added in  the web.config to increase the maxJsonLength property:

 <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="500000">
        </jsonSerialization>
      </webServices>
    </scripting>
  </system.web.extensions>

We also tried to increase the maxJsonLength value. But still  getting the same error.

My code:

.aspx page:

<telerik:RadGrid ID="RadGrid1" runat="server" Skin="" Width="97%" GridLines="None"
        ShowHeader="False">
        <MasterTableView HierarchyDefaultExpanded="True" HierarchyLoadMode="Client" DataKeyNames="ID,ParentScheduleID"
            Width="100%" AutoGenerateColumns="False">
            <SelfHierarchySettings ParentKeyName="ParentScheduleID" KeyName="ID" MaximumDepth="2"  />
            <Columns>
                <telerik:GridBoundColumn DataField="ScheduleName" HeaderText="ScheduleName" UniqueName="ScheduleName">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

.aspx.cs:(code behind)

  protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {        

            BindGrid();
        }
    }

    public void BindGrid()
    {
        DBLayer objDbLayer= new DBLayer();    

        DataSet dsSchedules = objDbLayer.GetScheduleData(ProjectId);

        if (dsSchedules.Tables.Count > 0)
        {           
            RadGrid1.DataSource = dsSchedules.Tables[0];

            RadGrid1.DataBind();
        }


    }

kindly help to resolve this error.

Thanks & Regards,

Venkatraman Gururaj.

4 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 17 Oct 2008, 01:29 PM
Hello venkatraman,

Can you please provide little more details about your implementation? To how many records you are binding? You also may consider using HierarchyLoadMode=ServerOnDemand.

Regards,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
venkatraman
Top achievements
Rank 1
answered on 03 Nov 2008, 01:13 PM
Hi Rosen,

     Thanks for you reply and very sorry for the late reply.

   Actually i have been working with Schedule kind of concept, where i can have List of schedule and child schedules. A child schedule can have more and more childs ...like a Treeview.

  currently i have around 550 records in a table. which also has self-referenced column called ParentScheduleId

As i work around this ,

HierarchyLoadMode=ServerOnDemand (with paging), if i click on (+ sign) to load the child rows, the child rows are not getting populated, and page is getting post back and  not displaying any rows. But grid shows simply empty.

HierarchyLoadMode=Client, is also working only if i have less then 20 fields, more than 20 fields returns the same error..........

"Error during serialization or deserialization using the JSON ...."

Waiting for your response.......

Thanks & Regards,

Venkatraman Gururaj.
 
0
Sebastian
Telerik team
answered on 04 Nov 2008, 09:16 AM
Hi venkatraman,

It seems that you are using simple binding with DataBind() calls to populate the grid. I suggest you use advanced binding with NeedDataSource handling as shown in the self-referencing hierarchy demo:

http://demos.telerik.com/ASPNET/Prometheus/Grid/Examples/Hierarchy/SelfReferencing/DefaultCS.aspx

and verify that the conventions for self-referencing settings are fulfilled with your configuration:

http://www.telerik.com/help/aspnet-ajax/grdselfreferencinghierarchy.html

Also make sure that you are using the latest version 2008.2.1001 of RadControls for ASP.NET AJAX.

Best,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
akshay
Top achievements
Rank 1
commented on 15 Nov 2024, 04:29 PM

I have this exception. please suggest    

<telerik:RadGrid ID="radGrid" runat="server" AllowPaging="True"  AllowSorting="True" ExportSettings-Excel-Format="ExcelML"
          AutoGenerateColumns="False" AllowAutomaticInserts="False" ShowStatusBar="True" PageSize="20"  GridLines="None" OnItemDataBound="radGrid_ItemDataBound"
          OnItemCommand="radGrid_ItemCommand">
          <ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="false"  >
          <Selecting AllowRowSelect="false" />
          </ClientSettings>
          <PagerStyle Mode="NumericPages" AlwaysVisible="true"></PagerStyle>
           <ExportSettings HideStructureColumns="true"  FileName="IncidentReport" IgnorePaging="true" OpenInNewWindow="true" ExportOnlyData="true" />  
          <MasterTableView Width="100%" CommandItemDisplay="Top">
          <CommandItemSettings AddNewRecordText="Add New Report" ShowAddNewRecordButton="false" ShowExportToExcelButton="true" ShowRefreshButton="true"/>
              <Columns>
              <telerik:GridBoundColumn DataField="reportGroup" HeaderText="ReportType" UniqueName="reportGroup" SortExpression="reportGroup" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>


 DataTable dt = dal.GetXXXX(); // returns 8 columns with  61,000 records 

 radGrid.DataSource = dt.DefaultView;
 if (dt.Columns["xxx"] == null)
 { 
     RadGridSubIncidents.Columns.FindByUniqueName("xxx").Visible = false;
 }

 radGrid.DataBind();      

 

 

exception

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentException: Error serializing value 'Table1' of type 'System.Data.DataTable.' ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.     at System.Text.StringBuilder.ToString()     at System.IO.StringWriter.ToString()     at System.Data.DataSet.GetRemotingDiffGram(DataTable table)     at System.Data.DataTable.SerializeDataTable(SerializationInfo info, StreamingContext context, Boolean isSingleTable, SerializationFormat remotingFormat)     at System.Data.DataTable.GetObjectData(SerializationInfo info, StreamingContext context)     at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)     at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)     at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)     at System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value)     --- End of inner exception stack trace ---     at System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value)     at System.Web.UI.ObjectStateFormatter.Serialize(Stream outputStream, Object stateGraph)     at System.Web.UI.ObjectStateFormatter.Serialize(Object stateGraph, Purpose purpose)     at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter2.Serialize(Object state, Purpose purpose)     at System.Web.UI.Util.SerializeWithAssert(IStateFormatter2 formatter, Object stateGraph, Purpose purpose)     at System.Web.UI.HiddenFieldPageStatePersister.Save()     at System.Web.UI.Page.SavePageStateToPersistenceMedium(Object state)     at System.Web.UI.Page.SaveAllState()     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)     at System.Web.UI.Page.HandleError(Exception e)     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)     at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)     at System.Web.UI.Page.ProcessRequest()     at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)     at System.Web.UI.Page.ProcessRequest(HttpContext context)     at ASP.account_default_aspx.ProcessRequest(HttpContext context)     at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()     at System.Web.HttpApplication.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0()     at System.Web.HttpApplication.StepInvoker.Invoke(Action executionStep)     at System.Web.HttpApplication.StepInvoker.<>c__DisplayClass4_0.<Invoke>b__0()     at Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule.OnExecuteRequestStep(HttpContextBase context, Action step)     at System.Web.HttpApplication.<>c__DisplayClass284_0.<OnExecuteRequestStep>b__0(Action nextStepAction)     at System.Web.HttpApplication.StepInvoker.Invoke(Action executionStep)     at System.Web.HttpApplication.StepInvoker.<>c__DisplayClass4_0.<Invoke>b__0()     at Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule.OnExecuteRequestStep(HttpContextBase context, Action step) in /_/WEB/Src/Web/Web/ApplicationInsightsHttpModule.cs:line 164     at System.Web.HttpApplication.<>c__DisplayClass284_0.<OnExecuteRequestStep>b__0(Action nextStepAction)     at System.Web.HttpApplication.StepInvoker.Invoke(Action executionStep)     at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)     at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

0
Rumen
Telerik team
answered on 18 Nov 2024, 08:47 AM

Hi Akshay,

The System.OutOfMemoryException exception you are encountering is a generic .NET OutOfMemoryException related to the serialization of a large DataTable. Here's a breakdown of what might be causing this issue and potential solutions:

  • Limit ViewState Usage: The error stack trace indicates that the issue might be related to the ViewState. Consider disabling ViewState for the RadGrid if it is not needed, or minimize the amount of data stored in it. You can do this by setting EnableViewState="false" on the RadGrid if you do not rely on ViewState for postback operations.

  • Optimize Data Loading: Consider loading only the data necessary for the current page or view. This can be achieved by implementing server-side paging and data loading using the NeedDataSource event. Ensure proper paging is enabled on your RadGrid to reduce the amount of data being loaded into memory:

    radGrid.PageSize = 50;
    radGrid.AllowPaging = true;

     

  • Increase Application Memory: As a temporary measure, you might consider increasing the memory available to your application. However, this is not a long-term solution and should be done with caution.

  • Check DataTable Usage: Review the DataTable usage to see if you can optimize it by reducing the number of columns or rows, or by using a more memory-efficient data structure.

  • Check web.config for maxRequestLength and maxAllowedContentLength settings. Update if necessary:

    <system.web>
      <httpRuntime maxRequestLength="51200" />
    </system.web>

Here's a code snippet to disable ViewState if you decide to go this route:

<telerik:RadGrid ID="radGrid" runat="server" EnableViewState="false" AllowPaging="True" PageSize="20" ...>
    <MasterTableView ...>
        ...
    </MasterTableView>
</telerik:RadGrid>

Implementing these suggestions should help mitigate the OutOfMemoryException by reducing the memory footprint of your application. If the problem persists, consider opening a support ticket and providing a smaller, runnable example to help further diagnose the issue.

 

    Regards,
    Rumen
    Progress Telerik

    Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
    Tags
    Grid
    Asked by
    venkatraman
    Top achievements
    Rank 1
    Answers by
    Rosen
    Telerik team
    venkatraman
    Top achievements
    Rank 1
    Sebastian
    Telerik team
    Rumen
    Telerik team
    Share this question
    or