-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 1.10
-
Component/s: Serialization
-
Environment:C# Driver 1.10.0.62, mongo 2.6.10 on Ubuntu
Customer reported this issue. They receive an exception when the driver attempts to deserialize documents:
Failed EXCEPTION: System.IO.FileFormatException: An error occurred while deserializing the Fields property of class Expected element name to be '_t', not '_v'. ---> System.IO.FileFormatException: Expected element name to be '_t', not '_v'. at MongoDB.Bson.IO.BsonReader.VerifyName(String expectedName) at MongoDB.Bson.Serialization.Serializers.EnumerableSerializerBase`1.Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) at MongoDB.Bson.Serialization.BsonClassMapSerializer.DeserializeMemberValue(BsonReader bsonReader, BsonMemberMap memberMap) — End of inner exception stack trace — at MongoDB.Bson.Serialization.BsonClassMapSerializer.DeserializeMemberValue(BsonReader bsonReader, BsonMemberMap memberMap) at MongoDB.Bson.Serialization.BsonClassMapSerializer.Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) at MongoDB.Bson.Serialization.Serializers.EnumerableSerializerBase`1.Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) at MongoDB.Bson.Serialization.BsonClassMapSerializer.DeserializeMemberValue(BsonReader bsonReader, BsonMemberMap memberMap)
Customer provided code sample:
Here's the call stack:
at MongoDB.Bson.IO.BsonReader.VerifyName(String expectedName) at MongoDB.Bson.Serialization.Serializers.EnumerableSerializerBase`1.Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) at MongoDB.Bson.Serialization.BsonClassMapSerializer.DeserializeMemberValue(BsonReader bsonReader, BsonMemberMap memberMap) --- End of inner exception stack trace --- at MongoDB.Bson.Serialization.BsonClassMapSerializer.DeserializeMemberValue(BsonReader bsonReader, BsonMemberMap memberMap) at MongoDB.Bson.Serialization.BsonClassMapSerializer.Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) at MongoDB.Bson.Serialization.Serializers.EnumerableSerializerBase`1.Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) at MongoDB.Bson.Serialization.BsonClassMapSerializer.DeserializeMemberValue(BsonReader bsonReader, BsonMemberMap memberMap) --- End of inner exception stack trace --- at MongoDB.Bson.Serialization.BsonClassMapSerializer.DeserializeMemberValue(BsonReader bsonReader, BsonMemberMap memberMap) at MongoDB.Bson.Serialization.BsonClassMapSerializer.Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) at MongoDB.Bson.Serialization.BsonClassMapSerializer.Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) at MongoDB.Driver.Internal.MongoReplyMessage`1.ReadBodyFrom(BsonBuffer buffer) at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage[TDocument](BsonBinaryReaderSettings readerSettings, IBsonSerializer serializer, IBsonSerializationOptions serializationOptions) at MongoDB.Driver.Operations.QueryOperation`1.GetFirstBatch(IConnectionProvider connectionProvider) at MongoDB.Driver.Operations.QueryOperation`1.Execute(IConnectionProvider connectionProvider) at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer) at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector) at OT.GC.DataMart.ETL.ReservationHistory.Repository.MongoDb.MongoDbReservationHistoryRepository.Get(Int64 rid, String reservationId)
and also this reduced sample which reproduces the error:
namespace WikiExampleConsole { public class TestClass { public object SomeData; } class Program { static void Main(string[] args) { string rawJsonTFirst = "{ \"SomeData\" : { \"_t\" : \"System.Object[]\", \"_v\" : [] } }"; Console.WriteLine("_t first {0}", BsonSerializer.Deserialize<TestClass>(rawJsonTFirst)); // succeeds string rawJsonVFirst = "{ \"SomeData\" : { \"_v\" : [], \"_t\" : \"System.Object[]\" } }"; Console.WriteLine("_v first {0}", BsonSerializer.Deserialize<TestClass>(rawJsonVFirst)); // throws } } }