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

MaxJsonLength exceeded / Self Referencing

10 Answers 1092 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carsten Koster
Top achievements
Rank 2
Carsten Koster asked on 11 Apr 2011, 04:07 PM
Hi there,

i encountered a (hopefully) small problem when using the radgrid control to display hierarchical self-referencing data.

I have an XML-Datasource that  contains around 1000 items. Each item has 30 attributes. There are 4 levels of hierarchy in the data.
e.g.

Item 1 (ID = 0, PARENT_ID = null)
---> Item 2(ID = 1, PARENT_ID = 0)
--------> Item 3 (ID = 2, PARENT_ID = 1)
...

The RadGrid is configured to use Databinding by the NeedDataSource event and self-referencing (id and id_parent). Where the datasource  property is set to the aforementioned XML-Datasource. As Soon as the XML contains 800 lines or more an InvalidOperationException is thrown:

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


I have already set the <jsonSerialization maxJsonLength="2147483644" /> value to the maximum and I am pretty sure that the data payload should not reach that value (2 Gb??). Also when I manually instance a System.Web.Script.Serialization.JavaScriptSerializer() it tells me the MaxJsonLength is only 2 MB but as far as I can tell that is by design.

I hope you can provide with some hints on how to proceed in this matter (Switching to a HierarchyLoadMode othern than Client, is unfortunately not an option.

Thank you for you support.

Regards.

---
Edit: Added the hint that I am using self referencing which was previously only contained in the title of the post.

10 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 15 Apr 2011, 07:56 AM
Hello Carsten,

Could you please try using HierarchyLoadMode=ServerOnDemand  and let me know if the issue still exists. Also could you please verify that you use the 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

Additionally could you please check what is the result when you bind the RadTreeList control to the same
datasource. Using the RadTreeList control is recommended in the case when you want to show self referencing data.

Looking forward for your reply.

Kind regards,
Radoslav
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Carsten Koster
Top achievements
Rank 2
answered on 15 Apr 2011, 08:44 AM
Hello Radoslav,

thank you for your reply.

Here are the answers to your questions:

1. Yes the Problem does not arise if the grid is set to ServerOnDemand. But as I wrote in my original posting it's not an option as it causes other Problems.

2. I've checked the requirements and It seems that they are fulfilled. And like I wrote aboute "The RadGrid is configured to use Databinding by the NeedDataSource event" so I am using advanced Databining.

3. Thank you for you suggestion I will evaluate if the TreeList control completes all the requirements I have. At a first glance some desired functionality seems to be missing: Excel-Export and Filtering.

I will try to bind to a TreeList and post my findings.

Thank you.

Regards

0
Carsten Koster
Top achievements
Rank 2
answered on 18 Apr 2011, 03:44 PM
Hi again,

I've evaluated the usage of a radtreelist now. It unfortunately it does not match our requirements.

With some hacking I was however able to get the radgrid to behave accordingly to our needs.

There is however still a small problem: As described it is bound via the usage of a XMLDataSource. When
trying to sort a column that contains numbers it sorts them like strings. Is it possible to tell the Control
to sort relative to the Datatype of the column? I've tried to use an inline xsd schema description but
the grid seems to ignore it.

I tried to use a strongly typed DataTable before but that caused some of the grids functionality (filtering, sorting) to fail completly.

A little help would be greatly appreciated.

Regards.
0
Radoslav
Telerik team
answered on 20 Apr 2011, 07:55 AM
Hi Carsten,

Indeed, your observation is correct. In order for the grouping/filtering/sorting to work as expected, the field must be part of the datasource of the control. However all the data provided from the XmlDataSource control have String as a type. One possible option in this case is as follows. You can use the NeedDataSource event handler to populate the grid with data. From the code-behind, you can read the data from the xml, and prepare a datatable, with all the data. You can then pass this data as a datasource for the grid.

I hope this suggestion helps.

Best wishes,
Radoslav
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Carsten Koster
Top achievements
Rank 2
answered on 05 Jul 2011, 08:32 AM
Dear Telerik Team,

after some fiddling with the radgrid and some collection of data to display, the grid again presents me with the

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


error Message. Is it possible that you could change the radgrid to adhere to the maxJsonLength property of the web.config file? As it currently does seem to ignore it.

For your convenience here is a part of the stack trace
[InvalidOperationException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.]
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat) +578585
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat) +74
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj) +6
   Telerik.Web.UI.RadGrid.DescribeProperties(IScriptDescriptor descriptor) +3106
   Telerik.Web.UI.RadGrid.DescribeComponent(IScriptDescriptor descriptor) +49
   Telerik.Web.UI.RadCompositeDataBoundControl.Telerik.Web.IControl.DescribeComponent(IScriptDescriptor descriptor) +39
   Telerik.Web.UI.ScriptRegistrar.GetScriptDescriptors(Control control) +185
   Telerik.Web.UI.ScriptRegistrar.GetScriptDescriptors(WebControl control) +31
   Telerik.Web.UI.RadCompositeDataBoundControl.GetScriptDescriptors() +30
   Telerik.Web.UI.RadCompositeDataBoundControl.System.Web.UI.IScriptControl.GetScriptDescriptors() +33
   System.Web.UI.ScriptControlManager.RegisterScriptDescriptors(IScriptControl scriptControl) +128
   System.Web.UI.ScriptManager.RegisterScriptDescriptors(IScriptControl scriptControl) +49
   Telerik.Web.UI.RadCompositeDataBoundControl.RegisterScriptDescriptors() +66
   Telerik.Web.UI.RadCompositeDataBoundControl.RenderContents(HtmlTextWriter writer) +63
   Telerik.Web.UI.RadGrid.RenderContents(HtmlTextWriter writer) +94
   Telerik.Web.UI.GridBaseDataList.Render(HtmlTextWriter writer) +123

Thank you for your support.

Regards


0
Radoslav
Telerik team
answered on 08 Jul 2011, 07:54 AM
Hello Carsten,

Could you please elaborate a bit more on your scenario. What number do you set to the maxJsonLength?
Also what is the configuration of the maxJsonLength property which you put into your web.config file? It will be helpful if you could send us a small example where the described issue could be reproduced . You could open a formal support ticket from your Telerik account and attach a ZIP file there. Thus we will be able to debug the project and provide a solution.

Additionally please keep in mind that when using self-referencing hierarchy, RadGrid creates and maintains data relations for all your data items, involving multiple loops over multiple sets of data. Additionally, if you have relations resulting in multiple nested levels, this additionally slows execution down, as numerous nested tables need to be initialized and databound.
With such a large data we advise you to consider alternative visualization options or try to reduce the number of data RadGrid binds to. If other hierarchical visualization options like nested tables or nested view template are applicable, consider testing such setups too.

Looking forward for your reply.

Regards,
Radoslav
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Laxmi
Top achievements
Rank 1
answered on 01 Aug 2012, 12:15 AM
Hi,

We have the same problem as mentioned above using the Telerik Radgrid control for displaying hierarchiacal data. Whenever we select the page size as 50 for the grid, it throws this json serialization error.

Could anyone please suggest possible way out for this error?

Thanks,
Laxmi
0
Radoslav
Telerik team
answered on 06 Aug 2012, 08:15 AM
Hello Laxmi,

Based on the provided information it is hard to say what is causing the described issue on your end. Could you please send us a small runnable example which demonstrates it. Thus we will be able to debug the project and provide you with more to-the-point answer. At a meantime could you please try increasing the jsonSerialization.MaxJsonLength number into your web.config file and let me know if it issue still persists. More information you could find here:
http://stackoverflow.com/questions/1045984/javascriptserializer-maxjsonlength-exceeded-whats-the-best-practice-for-handli
http://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config
http://forums.asp.net/p/1356198/2782837.aspx

Looking forward for your reply.

Kind regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Martin
Top achievements
Rank 1
answered on 20 Dec 2012, 11:11 AM
Hello I have the same issue and your links on advanced binding are all dead.

I have already set the json max length to near the maximum possible value and the issue persists.

I believe we use simple binding, but as I said your links to your example projects are dead.

Please help us out here!
0
Radoslav
Telerik team
answered on 21 Dec 2012, 09:08 AM
Hello Martin,

Could you please elaborate a bit more on your scenario? Which features of the RadGrid are you using? Also if you use self-referencing hierarchy the better choice is to use RadTreeList control which is highly optimized for such scenarios? Also it will be helpful if you could send us a small runnable example where the problem could be reproduced.
Additionally I am pasting again the links to advanced data binding documentation article and online example:
http://www.telerik.com/help/aspnet-ajax/grid-advanced-data-binding.html
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/needdatasource/defaultcs.aspx

Looking forward for your reply.

Kind regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Carsten Koster
Top achievements
Rank 2
Answers by
Radoslav
Telerik team
Carsten Koster
Top achievements
Rank 2
Laxmi
Top achievements
Rank 1
Martin
Top achievements
Rank 1
Share this question
or