Here is the code that never ends (crashes at some point) because of a cyclic reference:
var list = new System.Collections.Generic.List<object>();
list.Add(list);
var bson = MongoDB.Bson.BsonValue.Create(list);
Is this a known issue?
This is not a practical use case, indeed. Collections with recursion are more likely created by mistake, at least in our database related context.
I do not think this should be fixed. But I propose to document this issue. Users should be informed and aware of this. The example above is silly, cyclic references may be much more subtle in practice.
- related to
-
CSHARP-424 When attempting to serialize an object with circular references detect that and throw a catchable exception instead of a fatal StackOverflowException
- Closed