[CSHARP-2558] Unable to determine the serialization information for decimal type with Update.Set Created: 21/Mar/19  Updated: 03/Apr/23  Resolved: 25/Jun/20

Status: Closed
Project: C# Driver
Component/s: BSON, Write Operations
Affects Version/s: 2.8.0
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Tim Arheit Assignee: Wan Bachtiar
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MongoDB version 4.0.6
.Core 2.2



 Description   

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)

 

 

 

 

 



 Comments   
Comment by Rachelle Palmer [ 25/Jun/20 ]

Hi there, thank you for reaching out to MongoDB. As this sounds more like a support issue, I wanted to give you some resources to get this question answered more quickly:

  • our MongoDB support portal, located at support.mongodb.com
  • our MongoDB community forums, located here
  • If you are an Atlas customer, there is free support offered 24/7 in the lower right hand corner of the UI.

Thank you!
Rachelle

Comment by Wan Bachtiar [ 05/Jun/19 ]

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:

Hi Tim,

The update code snippet that you've posted seems to be incorrect (typo?). The Amount part should have been x.Amount for the context to exist. Changing the example update line to x.Amount works for me in v2.8.x. Please note that if you don't include the Decimal128 serialisation it will default to string.

I've also noticed that you have another related question answered in CSHARP-2607. If you still have further question, please provide a minimal, complete, and reproducible code snippet.

Regards,
Wan.

Generated at Wed Feb 07 21:42:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.