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

C# MongoDB对象序列化,堆栈溢出异常,c#,serialization,mongodb,mongodb-.net-driver,C#,Serialization,Mongodb,Mongodb .net Driver,当我尝试将一个对象序列化为bson、json、bsondocument时,会出现堆栈溢出异常。该类引用其外部类,外部类引用其内部类。解决此问题的方法是什么?对象图在对象链上下有很多引用 BsonClassMap.RegisterClassMap<Document>(); BsonClassMap.RegisterClassMap<Section>(); Document _document = GetDocument();

当我尝试将一个对象序列化为bson、json、bsondocument时,会出现堆栈溢出异常。该类引用其外部类,外部类引用其内部类。解决此问题的方法是什么?对象图在对象链上下有很多引用

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

        Document _document = GetDocument();

        BsonDocument _bsondocument1 = _document.ToBsonDocument();

        string _hello4 = _documents[0].ToJson();
BsonClassMap.RegisterClassMap();
BsonClassMap.RegisterClassMap();
文档_Document=GetDocument();
BsonDocument_bsondocument1=_document.ToBsonDocument();
字符串_hello4=_文档[0].ToJson();
部分
引用了
文档
文档
部分


感谢您的帮助。

堆栈溢出异常是预期的行为,因为对象图中存在循环引用。重构设计以避免循环路径。我不知道还有什么别的办法可以解决它