简体   繁体   English

MongoDB对象序列化,堆栈溢出异常

[英]MongoDB object serialization, stack overflow exception

I'm getting a stack overflow exception when I try to serialize an object to bson, json, bsondocument. 当我尝试将对象序列化为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 . Section引用了DocumentDocument引用了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. 我不知道有其他解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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