简体   繁体   中英

MongoDB object serialization, stack overflow exception

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM