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

How to resolve "RecursionLimit was excedeed" ?

10 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sébastien
Top achievements
Rank 1
Sébastien asked on 11 Oct 2010, 10:14 AM
Hello,
In using the "Grid" components to see a list of datas, an error is thrown by a javascript telerik file, "RecursionLimit was excedeed". Any idea ? Thx

10 Answers, 1 is accepted

Sort by
0
Sébastien
Top achievements
Rank 1
answered on 15 Oct 2010, 08:20 AM
I think it's happened where an object is too "complex" (with some sub objects, which have some sub objects...). Perhaps the JSON file is too long, the MVC Grid can' read it ... Any idea ? Thanks !
0
Sébastien
Top achievements
Rank 1
answered on 15 Oct 2010, 08:40 AM
An exception is thrown by the JavascriptSerializer.Serialize method, apparently when the object is too  complex. I try put a max value on the RecursionLimit and MaxJsonLength properties, but it doesn't work...
0
Rosen
Telerik team
answered on 15 Oct 2010, 08:47 AM
Hi S├ębastien,

Usually such error may occur when the built-in JSON serializer tries to serialize an object graph which does have circular references. For example type A has a property of type B which has a property of type A.
In order to workaround this problem you may consider using a ViewModel in which such dependencies does not exists. Another approach will be to increase the RecursionLimit.

All the best,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sébastien
Top achievements
Rank 1
answered on 18 Oct 2010, 01:49 PM
I'll find another solution in fact, thanks
0
Lasse
Top achievements
Rank 1
answered on 25 May 2011, 12:33 PM
Would you consider implementing a property for the Telerik MVC Grid, so it is possible to pass a list of propertynames that should be ignored by the grid?

For example:

@{
 
Html.Telerik().Grid<FileInfo>(Model)
.Name("FileGrid")
.DataKeys(keys => keys.Add(f => f.FullName))
.IgnoreProperties(new string[]{ "Directory", "Attributes" })
.Columns(columns =>
{
    columns.Bound(o => o.Name).Width(60);
    columns.Bound(o => o.LastWriteTime).Width(60); 
})
.DataBinding(dataBinding =>
{
    dataBinding.Ajax().Select("_AjaxGrid", "FileModule").Enabled(true);
})
.Footer(true)
.Render();
 
}
0
Atanas Korchev
Telerik team
answered on 25 May 2011, 02:05 PM
Hi Mikkel,

 Unfortunately there is no way to tell the JavaScriptSerializer which properties to ignore. The latter is being initialized internally by ASP.NET MVC and we don't have any control over it.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Lasse
Top achievements
Rank 1
answered on 25 May 2011, 02:08 PM
So you do not have any code that iterates properties recursively?
0
Atanas Korchev
Telerik team
answered on 25 May 2011, 02:09 PM
Hi Mikkel,

 No, we don't. The ASP.NET MVC JsonResult class which the grid uses to return the model as JSON creates a JavaScriptSerializer internally which in turn cannot serialize recursive objects. 

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vesselin Obreshkov
Top achievements
Rank 2
answered on 07 Nov 2011, 05:38 AM
You can try using Json.NET instead of the default JSON serializer. The latest versions of Json.NET can serialize objects with circular references:

http://james.newtonking.com/projects/json/help/PreserveObjectReferences.html 
0
Linas
Top achievements
Rank 1
answered on 12 Nov 2011, 08:09 PM
Perhaps the simplest way to avoid serialization problems (circular reference, recursion) is to add [ScriptIgnore] atribute (namespace: System.Web.Script.Serialization) to some of your navigational properties:
[ScriptIgnore] // do not serialize to JSON in order to prevent cyclic references
public ICollection<ConditionPresetFilter> Filters { get; set; }
This prevents the serializer going over your complete graph of related objects.
Tags
Grid
Asked by
Sébastien
Top achievements
Rank 1
Answers by
Sébastien
Top achievements
Rank 1
Rosen
Telerik team
Lasse
Top achievements
Rank 1
Atanas Korchev
Telerik team
Vesselin Obreshkov
Top achievements
Rank 2
Linas
Top achievements
Rank 1
Share this question
or