2

Closed

SerializeValue/SerializeList stack overflow with active reference handling

description

Json.net 4.5.11 has a major issue where you can get a StackOverflowException even if PreserveReferencesHandling is nset to PreserveReferencesHandling.All and ReferenceLoopHandling is set to ReferenceLoopHandling.Error.

The callstack shows SerializeValue, SerializeList, SerializeValue, SerializeList, SerializeValue, SerializeList and so on.

When I take a look at the source code, I see that there is a call from SerializeValue to SerializeList when the contract type is a one-dimensional array and SerializeList calls SerializeValue for each item in the list. This looks correct so far, but when you follow these calls you can see that there is no checking for known references.

I am a bit unsure why, but I think that the problem is that for JsonContainerContract instances, the IsReference property is never set automatically, but only from attributes. So, when contracts are auto-generated from reflection, IsReference is always false. But it should be true for classes and arrays....?
Closed Jan 30, 2013 at 10:17 AM by JamesNK

comments

JamesNK wrote Jan 22, 2013 at 9:39 AM

Could you comment or attached a simple example of a class that causes the error?