Migrating to EPiServer 10 is causing Circular reference



Migrating to EPiServer 10 is causing Circular reference in all JSON Serializations i use.

whether i use JavascriptSerializer, Newtonsoft, Jil.. i get a circular reference error while serializing a list of PageTypes.

I can loop through the objects and get the properties i only need and build a JSON. But this is a huge project that serializes objects lots of times. so rewriting the code seems almost impossible.

Any idea how to solve that?

Apr 24, 2017 11:35
Jeroen Stemerdink
Member since: 2009

Ofcourse I don't know excactly what your list contains, but have you tried adding the following?

return JsonConvert.SerializeObject(results, Formatting.Indented, 
    new JsonSerializerSettings { 
        ReferenceLoopHandling = ReferenceLoopHandling.Ignore 
Apr 24, 2017 15:00

Hi  There,

When i add the ReferenceLoopHandling i receive this error:

[NullReferenceException: Object reference not set to an instance of an object.]
EPiServer.Core.PropertyContentReference.get_ID() +13
GetID(Object ) +44
Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target) +383

[JsonSerializationException: Error getting value from 'ID' on 'EPiServer.Core.PropertyPageReference'.]

Apr 24, 2017 17:54

I would like to add also that the ID is not null. It has value. And that the same code is working in EpiServer 8.

Apr 25, 2017 9:00
Jeroen Stemerdink
Member since: 2009

Have you tried adding

NullValueHandling = NullValueHandling.Ignore

to the settings as well?

Apr 25, 2017 10:26

Jeroen, Thanks for the fast reply.

I still get the NullReferenceException even after having NullValueHandling ignored in the settings. This is really strange. 

Apr 25, 2017 11:26
Adam Finzel
Member since: 2015

Sorry to rekindle an old thread but did you get this working?  I see that the GetID doesn't do a null check in their code.

Mar 08, 2019 9:29