Hi Robert,
On Jan 25, 4:05 am, Robert Stam <
rstam10...@gmail.com> wrote:
> I'm assuming you are using an older version of the driver, but if not
> we can look into this further.
Sorry, I should have said.
Driver is 0.9.0.3992
MongoDb Win32 x86-64 1.6.5
> A note about your Foo class containing a list of Foos: this is OK as
> long as the object graph is a tree. If any of those nested Foos are
> references to Foos further up on the tree you will get a
> StackOverflowException when serializing. The BsonSerializer does not
> handle self referencing object graphs.
Yeah, the above is a minimal example, it exhibits the same problem as
my full tree, which is more like (still somewhat elided):
public interface INode<T> {
INodeList<T> Children { get; set; }
INode<T> Parent { get; set; }
T Value { get; set; }
...
}
public interface INodeList<T> : IList<INode<T>> {
INode<T> Parent { get; set; }
INode<T> Add( T value );
...
}
The implementation ensures that it can't be self-referencing.
Also, I just tried serializing a FooList on it's own and that didn't
work either. So it turns out we can reduce the minimal test case
further:
public class FooList : List<string> {
public string Id;
}
var fooListCollection =
database.GetCollection<FooList>( typeof( FooList ).Name );
var fooList = new FooList{ Id = "fooList" };
fooList.Add( "fooListItem" );
fooListCollection.Save( fooList );
{ "_id" : "fooList", "Capacity" : 4 }