All
Consider this example:
private class CollectionHolder
{
public ObjectId Id { get; set; }
public MyCollection Collection { get; set; }
}
private class MyCollection : List<int>
{
public MyCollection(List<int> a)
{
this.AddRange(a);
}
}
private static void CollectionTest()
{
var collection = database.GetCollection<MyCollection>("collectionTest");
collection.RemoveAll();
collection.Save(new CollectionHolder { Collection = new MyCollection(new List<int> { 1, 2, 3, 4, 5 }) });
var x = collection.AsQueryable().First(); //exception!
x.ForEach(Console.WriteLine);
}
The marked line throws exception
An error occurred while deserializing the Collection property of class MongoDriverTest.Program+CollectionHolder: An error occurred while deserializing the Capacity property of class MongoDriverTest.Program+MyCollection: Object reference not set to an instance of an object.
I am not sure, is this a bug in 10gen mongo driver, or is this impossible to implement?
How do You think, should this be posted as a bug?
Moreover -- what is the best way to avoid such kind of errors?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…