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

System.FormatException. If result of $divide it is not integer value exception be thrown when Aggregate.Project are using

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.10.1
    • Component/s: Command Operations
    • None

       

      var settings = MongoClientSettings.FromUrl(new MongoUrl("mongodb://localhost:27017/?readPreference=primary&appname=MongoDB%20Compass%20Community&ssl=false"));
                  var client = new MongoClient(settings);
                  var database = client.GetDatabase("ZipDataSet");
                  var collection = database.GetCollection<Zip>("Zips");            await collection.InsertManyAsync(new List<Zip>
                  {
                      new Zip
                      {
                          ZipCode = 1,
                          Population=100,
                      },
                      new Zip
                      {
                          ZipCode = 2,
                          Population=200,
                      },
                      new Zip
                      {
                          ZipCode = 3,
                          Population=300,
                      },
                  });            
      
                 //this is expected behavior
                  var resultFind = await collection.Find(new BsonDocument()).Project(el => new { 
                      DividedPopulation = el.Population / 23
                  }).ToListAsync();
      
                  //this is throw exception
                  var resultProject = await collection.Aggregate().Project(el => new {
                      DividedPopulation = el.Population / 23
                  }).ToListAsync();
      
      
      

       

       

      Exception:

       

        Message: 
          System.FormatException : An error occurred while deserializing the DividedPopulation property of class <>f__AnonymousType0`1[[System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]: Truncation resulted in data loss.
          ---- MongoDB.Bson.TruncationException : Truncation resulted in data loss.
        Stack Trace: 
          BsonClassMapSerializer`1.DeserializeMemberValue(BsonDeserializationContext context, BsonMemberMap memberMap)
          BsonClassMapSerializer`1.DeserializeClass(BsonDeserializationContext context)
          BsonClassMapSerializer`1.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
          IBsonSerializerExtensions.Deserialize[TValue](IBsonSerializer`1 serializer, BsonDeserializationContext context)
          EnumerableSerializerBase`2.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
          IBsonSerializerExtensions.Deserialize[TValue](IBsonSerializer`1 serializer, BsonDeserializationContext context)
          CursorDeserializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
          IBsonSerializerExtensions.Deserialize[TValue](IBsonSerializer`1 serializer, BsonDeserializationContext context)
          AggregateResultDeserializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
          IBsonSerializerExtensions.Deserialize[TValue](IBsonSerializer`1 serializer, BsonDeserializationContext context)
          CommandUsingCommandMessageWireProtocol`1.ProcessResponse(ConnectionId connectionId, CommandMessage responseMessage)
          CommandUsingCommandMessageWireProtocol`1.ExecuteAsync(IConnection connection, CancellationToken cancellationToken)
          ServerChannel.ExecuteProtocolAsync[TResult](IWireProtocol`1 protocol, ICoreSession session, CancellationToken cancellationToken)
          RetryableReadOperationExecutor.ExecuteAsync[TResult](IRetryableReadOperation`1 operation, RetryableReadContext context, CancellationToken cancellationToken)
          ReadCommandOperation`1.ExecuteAsync(RetryableReadContext context, CancellationToken cancellationToken)
          AggregateOperation`1.ExecuteAsync(RetryableReadContext context, CancellationToken cancellationToken)
          AggregateOperation`1.ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken)
          OperationExecutor.ExecuteReadOperationAsync[TResult](IReadBinding binding, IReadOperation`1 operation, CancellationToken cancellationToken)
          MongoCollectionImpl`1.ExecuteReadOperationAsync[TResult](IClientSessionHandle session, IReadOperation`1 operation, ReadPreference readPreference, CancellationToken cancellationToken)
          MongoCollectionImpl`1.AggregateAsync[TResult](IClientSessionHandle session, PipelineDefinition`2 pipeline, AggregateOptions options, CancellationToken cancellationToken)
          MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)
          IAsyncCursorSourceExtensions.ToListAsync[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)
          StatisticsEventRepository.SuperCustomLogicHere() line 81
          MongoRepositoryTests.DoNothing() line 27
          --- End of stack trace from previous location where exception was thrown ---
          ----- Inner Stack Trace -----
          RepresentationConverter.ToInt32(Double value)
          Int32Serializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
          IBsonSerializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
          IBsonSerializerExtensions.Deserialize(IBsonSerializer serializer, BsonDeserializationContext context)
          BsonClassMapSerializer`1.DeserializeMemberValue(BsonDeserializationContext context, BsonMemberMap memberMap)
      

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            niksan_la2@mail.ru Nikita Del
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: