[CSHARP-2227] NullReferenceException when setting int[] to NULL Created: 27/Mar/18  Updated: 13/Jul/20  Resolved: 13/Jul/20

Status: Closed
Project: C# Driver
Component/s: Serialization
Affects Version/s: 2.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Artem Meron Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows Server 2016 / 10



 Description   

Assigning null to int[] property on data entity,
causing exception in the driver code,

System.NullReferenceException: Object reference not set to an instance of an object.
at MongoDB.Driver.FieldValueSerializerHelper.ConvertIfPossibleSerializer2.TryConvertValue(TFrom value, TTo& convertedValue)
at MongoDB.Driver.FieldValueSerializerHelper.ConvertIfPossibleSerializer2.Serialize(BsonSerializationContext context, BsonSerializationArgs args, TFrom value
at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Serialize[TValue](IBsonSerializer1 serializer, BsonSerializationContext context, TValue value)
at MongoDB.Driver.OperatorUpdateDefinition2.Render(IBsonSerializer1 documentSerializer, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.CombinedUpdateDefinition1.Render(IBsonSerializer1 documentSerializer, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.MongoCollectionImpl1.ConvertWriteModelToWriteRequest(WriteModel1 model, Int32 index)
at System.Linq.Enumerable.<SelectIterator>d__52.MoveNext()
at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation..ctor(CollectionNamespace collectionNamespace, IEnumerable1 requests, MessageEncoderSettings messageEncoderSettings)
at MongoDB.Driver.MongoCollectionImpl1.CreateBulkWriteOperation(IEnumerable1 requests, BulkWriteOptions options)
at MongoDB.Driver.MongoCollectionImpl1.<BulkWriteAsync>d__26.MoveNext()
-- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.MongoCollectionImpl1.d__911.MoveNext()
-- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at MongoDB.Driver.MongoCollectionBase1.d__93.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

see my comment here,

https://github.com/mongodb/mongo-csharp-driver/commit/8fe8e0a2696a4255f0567a25842223d7be42ca27#diff-bf7ce5c4325e843b46a8496e92a71805



 Comments   
Comment by Ian Whalen (Inactive) [ 26/Nov/18 ]

artem@jellybtn.com this looks like a bug but can you please give us sample code to reproduce it?

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