ASP.NET JSON Self Referencing Properties

In object-oriented languages, an object can hold a reference to itself in a property, and there’s no problem with that. However, when you go to serialize that object, you run into issues.

An object with a self-referencing property that loops back to itself would cause an infinite loop and crash when trying to serialize it. Here’s how to avoid the error in ASP.NET.

I’d recommend against the idea in the first place, opting instead for simple data types, but this is here if you need it.

View code on GitHub

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s