-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Environment:Win XP. .NET 3.5
-
Major Change
Sometime between 11/5 and now this broke. Did a pull and got the latest code now the deserialization is broken.
Steps to reproduce:
1. Create two classes, one that derives from another. (ie class B: A)
2. Set up mapping through attributes, or just use default.
3. Create two instances of B and save to a collection.
4. Query the collection specifying the custom type db.GetCollection<A>("myCollection").Find(...) (make sure this query returns at least 2 documents of type B).
This fails at the deserialization stage on the 2nd type B document.
Seems to be an issue with the bsonReader's buffer index not getting updated properly b/c it is set to EndOfDocument when it tries to deserialize the 2nd document causing a the actualType to default to the nominalType and therefore causes failure when deserializing. I stepped through the code a bit and this is the beginning of where everything goes bad:
// BsonClassMapSerializer.cs line 57
var actualType = discriminatorConvention.GetActualType(bsonReader, nominalType);
The actualType comes back the same as the nominalType (A) when it should come back as B. Since the data stored in the db is of type B, the properties cant get set and an exception gets thrown.
Stack Trace:
at MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.Deserialize(BsonReader bsonReader, Type nominalType) in C:\DEVELOPMENT\trunk\Beast\mongo-csharp-driver\Bson\DefaultSerializer\BsonClassMapSerializer.cs:line 91
at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(BsonReader bsonReader, Type nominalType) in C:\DEVELOPMENT\trunk\Beast\mongo-csharp-driver\Bson\Serialization\BsonSerializer.cs:line 70
at MongoDB.Bson.Serialization.BsonSerializer.Deserialize[T](BsonReader bsonReader) in C:\DEVELOPMENT\trunk\Beast\mongo-csharp-driver\Bson\Serialization\BsonSerializer.cs:line 46
at MongoDB.Driver.Internal.MongoReplyMessage`1.ReadFrom(BsonBuffer buffer) in C:\DEVELOPMENT\trunk\Beast\mongo-csharp-driver\Driver\Internal\MongoReplyMessage.cs:line 88
at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage[TDocument]() in C:\DEVELOPMENT\trunk\Beast\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 291
at MongoDB.Driver.MongoCursor`2.MongoCursorEnumerator.GetReply(MongoRequestMessage message) in C:\DEVELOPMENT\trunk\Beast\mongo-csharp-driver\Driver\Core\MongoCursor.cs:line 487
at MongoDB.Driver.MongoCursor`2.MongoCursorEnumerator.GetFirst() in C:\DEVELOPMENT\trunk\Beast\mongo-csharp-driver\Driver\Core\MongoCursor.cs:line 452
at MongoDB.Driver.MongoCursor`2.MongoCursorEnumerator.MoveNext() in C:\DEVELOPMENT\trunk\Beast\mongo-csharp-driver\Driver\Core\MongoCursor.cs:line 369
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)