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

Filter with ReplaceOneAsync resuls in NullReferenceException

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4.3
    • Affects Version/s: 2.4.2
    • Component/s: API
    • None

      NullReferenceException results from the following code after upgrade to v2.4.2:

      System.NullReferenceException occurred
      Message: Exception thrown: 'System.NullReferenceException' in MongoDB.Bson.dll
      Additional information: Object reference not set to an instance of an object.
      

      Here's our C# code:

          public class FxRateDataDb : IFxRateDataDb
          {
              [BsonId]
              public string Id { get; set; }
      }
      
          public class MongoDbCollection<T, TId> : IDbCollection<T> where T : IId<TId>
          {
              private readonly IMongoCollection<T> _mongoCollection;
      
              public async Task ReplaceOneAsync(T item, bool upsert)
              {
                  await _mongoCollection.ReplaceOneAsync(x => Equals(x.Id, item.Id), item, new UpdateOptions {IsUpsert = upsert}); // NullReferenceException
              }
          }
      

      And here's the stack trace:

      >	MongoDB.Bson.dll!MongoDB.Bson.Serialization.IBsonSerializerExtensions.Serialize(MongoDB.Bson.Serialization.IBsonSerializer serializer, MongoDB.Bson.Serialization.BsonSerializationContext context, object value)	Unknown
       	MongoDB.Bson.dll!MongoDB.Bson.Serialization.IBsonSerializerExtensions.ToBsonValue(MongoDB.Bson.Serialization.IBsonSerializer serializer, object value)	Unknown
       	MongoDB.Driver.dll!MongoDB.Driver.Linq.Translators.PredicateTranslator.TranslateComparison(System.Linq.Expressions.Expression variableExpression, System.Linq.Expressions.ExpressionType operatorType, System.Linq.Expressions.ConstantExpression constantExpression)	Unknown
       	MongoDB.Driver.dll!MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(System.Linq.Expressions.Expression node)	Unknown
       	MongoDB.Driver.dll!MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(System.Linq.Expressions.Expression node, MongoDB.Bson.Serialization.IBsonSerializerRegistry serializerRegistry)	Unknown
       	MongoDB.Driver.dll!MongoDB.Driver.MongoCollectionImpl<SPMO.Providers.MarketData.FxRateDataDb>.ConvertWriteModelToWriteRequest(MongoDB.Driver.WriteModel<SPMO.Providers.MarketData.FxRateDataDb> model, int index)	Unknown
       	System.Core.dll!System.Linq.Enumerable.SelectIterator<MongoDB.Driver.WriteModel<SPMO.Providers.MarketData.FxRateDataDb>, MongoDB.Driver.Core.Operations.WriteRequest>(System.Collections.Generic.IEnumerable<MongoDB.Driver.WriteModel<SPMO.Providers.MarketData.FxRateDataDb>> source, System.Func<MongoDB.Driver.WriteModel<SPMO.Providers.MarketData.FxRateDataDb>, int, MongoDB.Driver.Core.Operations.WriteRequest> selector)	Unknown
       	MongoDB.Driver.Core.dll!MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.BatchHelper.FindOrderedRuns(int maxRunLength)	Unknown
       	MongoDB.Driver.Core.dll!MongoDB.Driver.Core.Misc.ReadAheadEnumerable<MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.Run>.ReadAheadEnumerator.MoveNext()	Unknown
       	MongoDB.Driver.Core.dll!MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.BatchHelper.GetBatches()	Unknown
       	MongoDB.Driver.Core.dll!MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.ExecuteAsync(MongoDB.Driver.Core.Bindings.IWriteBinding binding, System.Threading.CancellationToken cancellationToken)	Unknown
       	mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)	Unknown
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            moc777 Matthew O&#39;Connell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: