0

I'm getting a stack overflow exception when I try to serialize an object to bson, json, bsondocument. The class has references to its outer class and outer class references to its inner class. What is the way to fix this issue? The object graph has a lot of references up and down the object chain?

        BsonClassMap.RegisterClassMap<Document>();
        BsonClassMap.RegisterClassMap<Section>();

        Document _document = GetDocument();

        BsonDocument _bsondocument1 = _document.ToBsonDocument();

        string _hello4 = _documents[0].ToJson();

Class Section has reference to Document and Document has Sections.

Thanks for your help.

1 Answer 1

1

The stack overflow exception is the expected behavior as there is a circular reference in the object graph. Refactor your design to avoid a circular path. I am not aware of any other way to fix it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.