During serialization if there is a cycle in the object graph, a StackOverflowException is raised. Instead we should throw an InvalidOperationException or other exception TBD. StackOverflowException is non-recoverable.
To avoid this, we should use the MaxDepth setting. Note this setting is used during deserialization (where we throw a InvalidOperationException) but it currently is not used for serialization.