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
- depends on
-
CSHARP-1894 InvalidCastException in FieldValueSerializerHelper on implicit type casting
- Closed