Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-112

Make C# driver deserialize Doubles and LongNumber(Int64) in MongoDocuments to Int32s

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 0.7, 0.9
    • Fix Version/s: 0.9
    • Component/s: None
    • Labels:
      None
    • Environment:
      Visual Studio 2008
    • # Replies:
      1
    • Last comment by Customer:
      false

      Description

      If you do a db.collection.insert(

      {"Capacity" : new NumberLong(75)}

      ) and
      deserialize it from the Csharp driver you get an
      InvalidOperationException: ReadInt32 cannot be called when BsonType is:
      Int64. If I just enter a number javascript thinks it a float and I get a
      similar error.

      The Csharp drivers deserialization should be more forgiving. In the case of Int64 to int32, overflow should cause an exception to occur.
      In the case of double to int32, an exception should be thrown if fractional parts are truncated.

      Stack trace of the exception
      at MongoDB.Bson.IO.BsonBinaryReader.VerifyBsonType(String methodName,
      BsonType requiredBsonType) in D:\justin's
      projects\mongo-csharp\Bson\IO\BsonBinaryReader.cs:line 587
      at MongoDB.Bson.IO.BsonBinaryReader.ReadInt32() in D:\justin's
      projects\mongo-csharp\Bson\IO\BsonBinaryReader.cs:line 283
      at MongoDB.Bson.DefaultSerializer.Int32Serializer.Deserialize(BsonReader
      bsonReader, Type nominalType) in D:\justin's
      projects\mongo-csharp\Bson\DefaultSerializer\Serializers\BsonPrimitiveSeria lizers.cs:line
      418
      at
      MongoDB.Bson.DefaultSerializer.BsonBaseSerializer.Deserialize(BsonReader
      bsonReader, Type nominalType, Type actualType) in D:\justin's
      projects\mongo-csharp\Bson\DefaultSerializer\Serializers\BsonBaseSerializer .cs:line
      46
      at
      MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.DeserializeMember(Bso nReader
      bsonReader, Object obj, BsonMemberMap memberMap) in D:\justin's
      projects\mongo-csharp\Bson\DefaultSerializer\BsonClassMapSerializer.cs:line
      221
      at
      MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.Deserialize(BsonReade r
      bsonReader, Type nominalType, Type actualType) in D:\justin's
      projects\mongo-csharp\Bson\DefaultSerializer\BsonClassMapSerializer.cs:line
      95
      at
      MongoDB.Bson.DefaultSerializer.EnumerableSerializer`1.Deserialize(BsonReade r
      bsonReader, Type nominalType) in D:\justin's
      projects\mongo-csharp\Bson\DefaultSerializer\Serializers\CollectionGenericS erializers.cs:line
      68
      at
      MongoDB.Bson.DefaultSerializer.BsonBaseSerializer.Deserialize(BsonReader
      bsonReader, Type nominalType, Type actualType) in D:\justin's
      projects\mongo-csharp\Bson\DefaultSerializer\Serializers\BsonBaseSerializer .cs:line
      46
      at
      MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.DeserializeMember(Bso nReader
      bsonReader, Object obj, BsonMemberMap memberMap) in D:\justin's
      projects\mongo-csharp\Bson\DefaultSerializer\BsonClassMapSerializer.cs:line
      221
      at
      MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.Deserialize(BsonReade r
      bsonReader, Type nominalType, Type actualType) in D:\justin's
      projects\mongo-csharp\Bson\DefaultSerializer\BsonClassMapSerializer.cs:line
      95
      at
      MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.Deserialize(BsonReade r
      bsonReader, Type nominalType) in D:\justin's
      projects\mongo-csharp\Bson\DefaultSerializer\BsonClassMapSerializer.cs:line
      63
      at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(BsonReader
      bsonReader, Type nominalType) in D:\justin's
      projects\mongo-csharp\Bson\Serialization\BsonSerializer.cs:line 76
      at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Stream stream,
      Type nominalType) in D:\justin's
      projects\mongo-csharp\Bson\Serialization\BsonSerializer.cs:line 93
      at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Byte[] bytes,
      Type nominalType) in D:\justin's
      projects\mongo-csharp\Bson\Serialization\BsonSerializer.cs:line 84
      at MongoDB.Bson.Serialization.BsonSerializer.Deserialize[T](Byte[] bytes)
      in D:\justin's
      projects\mongo-csharp\Bson\Serialization\BsonSerializer.cs:line 58
      at
      Wunderman.EventRSVPSite.DataAccess.EventManager.GetEventLocations[T,t](Obje ctId
      id) in D:\justin's
      projects\LRT-MSC-O03023_EventRsvpSite\EventRSVPSite.DataAccess\EventManager .cs:line
      109
      at
      Wunderman.EventRSVPSite.Service.RsvpService.GetEventLocations(GetEventReque st
      request) in D:\justin's
      projects\LRT-MSC-O03023_EventRsvpSite\EventRSVPSite.Service\RsvpService.cs: line
      68
      at SyncInvokeGetEventLocations(Object , Object[] , Object[] )
      at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object
      instance, Object[] inputs, Object[]& outputs)
      at
      System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(Message Rpc&
      rpc)

        Activity

        • Comments
        Hide
        rstam Robert Stam added a comment -

        Int32Serialize will now convert Double or Int64 to Int32 and will only throw an exception if data loss occurs.

        Show
        rstam Robert Stam added a comment - Int32Serialize will now convert Double or Int64 to Int32 and will only throw an exception if data loss occurs.

          People

          • Assignee:
            rstam Robert Stam
            Reporter:
            zippy1981 Justin Dearing
            Participants:
            Last commenter:
            Rathi Gnanasekaran
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since reply:
              6 years, 31 weeks, 4 days ago
              Date of 1st Reply: