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

Unable to determine the serialization information for decimal type with Update.Set

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: 2.8.0
    • Component/s: BSON, Write Operations
    • None
    • Environment:
      MongoDB version 4.0.6
      .Core 2.2

      With Amount defined in the class as:

      [BsonIgnoreIfNull]
      public decimal? Amount { get; set; } = null;

      The following update returns throws the error: One or more errors occurred. (Unable to determine the serialization information for x => value(i3vDB.CollectionsTrans.Transaction).MerchantAmount.)

            await myCollection.UpdateOneAsync(x => x.Id == id,
      Builders<Transaction>.Update.Set(x => Amount, newValue)).ConfigureAwait(false);

       

      I am able to use the same logic to update bools, and other data types without issues.  I've tried with and without setting the BsonSerializer to support the new decimal format:

          BsonSerializer.RegisterSerializer(typeof(decimal), new DecimalSerializer(BsonType.Decimal128));
      BsonSerializer.RegisterSerializer(typeof(decimal?), new NullableSerializer<decimal>(new DecimalSerializer(BsonType.Decimal128)));

       

      I am able to load and save the object normally (.Find and .ReplaceOneAsync)

       

       

      Full error message:

      System.AggregateException : One or more errors occurred. (Unable to determine the serialization information for x => value(i3vDB.CollectionsTrans.Transaction).MerchantAmount.)
      ----> System.InvalidOperationException : Unable to determine the serialization information for x => value(i3vDB.CollectionsTrans.Transaction).MerchantAmount.
      at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
      at System.Threading.Tasks.Task.Wait()
      at Velocity.Common.Test.DynamicPayout.CalculateJournalEntries_CreditCardSale.CreditCardSale_Refund_Calculate(DateTime transactionDateTime, DateTime expectedDate) in C:\dbs\chargepayment\Blocks\Velocity\Common.Test\DynamicPayout\CalculateJournalEntries_CreditCardSale.cs:line 571
      --InvalidOperationException
      at MongoDB.Driver.ExpressionFieldDefinition`2.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry, Boolean allowScalarValueForArrayField)
      at MongoDB.Driver.OperatorUpdateDefinition`2.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)
      at MongoDB.Driver.MongoCollectionImpl`1.ConvertWriteModelToWriteRequest(WriteModel`1 model, Int32 index)
      at System.Linq.Enumerable.SelectIterator[TSource,TResult](IEnumerable`1 source, Func`3 selector)+MoveNext()
      at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
      at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
      at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation..ctor(CollectionNamespace collectionNamespace, IEnumerable`1 requests, MessageEncoderSettings messageEncoderSettings)
      at MongoDB.Driver.MongoCollectionImpl`1.CreateBulkWriteOperation(IEnumerable`1 requests, BulkWriteOptions options)
      at MongoDB.Driver.MongoCollectionImpl`1.BulkWriteAsync(IClientSessionHandle session, IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)
      at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)
      at MongoDB.Driver.MongoCollectionBase`1.UpdateOneAsync(FilterDefinition`1 filter, UpdateDefinition`1 update, UpdateOptions options, Func`3 bulkWriteAsync)

       

       

       

       

       

            Assignee:
            wan.bachtiar@mongodb.com Wan Bachtiar
            Reporter:
            tim.arheit@payschools.com Tim Arheit
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: