Uploaded image for project: 'Entity Framework'
  1. Entity Framework
  2. EF-192

ReloadAsync throws ArgumentNullException

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • 8.2.3
    • Affects Version/s: 8.1.1, 8.2.2, 8.2.3
    • None
    • None
    • Dotnet Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Description:

      When invoking `context.Entry(entity).ReloadAsync(cancellationToken)` on an entity in our MongoDB integration tests, an `ArgumentNullException` is thrown. This occurs during our test flow when we attempt to reload an entity that should have been updated by our background service, which processes messages from an Azure Service Bus (ASB) emulator.

      Expected Behavior:

      The ReloadAsync method should successfully reload the updated entity from MongoDB so that subsequent assertions (such as verifying the appended messages array) can be performed without having to re-query the entity explicitly.

      Actual Behavior:

      An `ArgumentNullException` is thrown during the call to `ReloadAsync`, as detailed in the following stack trace:

      ```
      System.ArgumentNullException: Value cannot be null. (Parameter 'expression')
      at System.Dynamic.Utils.ContractUtils.RequiresNotNull(Object value, String paramName, Int32 index)
      at System.Dynamic.Utils.ExpressionUtils.RequiresCanRead(Expression expression, String paramName, Int32 idx)
      at System.Linq.Expressions.Expression.Convert(Expression expression, Type type, MethodInfo method)
      at System.Linq.Expressions.Expression.MakeUnary(ExpressionType unaryType, Expression operand, Type type, MethodInfo method)
      at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
      at MongoDB.EntityFrameworkCore.Query.Visitors.MongoProjectionBindingExpressionVisitor.Visit(Expression expression)
      at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
      at MongoDB.EntityFrameworkCore.Query.Visitors.MongoProjectionBindingExpressionVisitor.Visit(Expression expression)
      at MongoDB.EntityFrameworkCore.Query.Visitors.MongoProjectionBindingExpressionVisitor.<VisitNewArray>b__14_0(Expression e)
      at System.Linq.Enumerable.IListSelectIterator`2.Fill(IList`1 source, Span`1 results, Func`2 func)
      at System.Linq.Enumerable.IListSelectIterator`2.ToArray()
      at System.Dynamic.Utils.CollectionExtensions.ToReadOnly[T](IEnumerable`1 enumerable)
      at System.Dynamic.Utils.ExpressionUtils.SameElements[T](IEnumerable`1& replacement, IReadOnlyList`1 current)
      at System.Linq.Expressions.NewArrayExpression.Update(IEnumerable`1 expressions)
      at MongoDB.EntityFrameworkCore.Query.Visitors.MongoProjectionBindingExpressionVisitor.VisitNewArray(NewArrayExpression newArrayExpression)
      at MongoDB.EntityFrameworkCore.Query.Visitors.MongoProjectionBindingExpressionVisitor.Visit(Expression expression)
      at MongoDB.EntityFrameworkCore.Query.Visitors.MongoProjectionBindingExpressionVisitor.Translate(MongoQueryExpression queryExpression, Expression expression)
      at MongoDB.EntityFrameworkCore.Query.Visitors.MongoQueryableMethodTranslatingExpressionVisitor.TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)
      at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
      at MongoDB.EntityFrameworkCore.Query.Visitors.MongoQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
      at MongoDB.EntityFrameworkCore.Query.Visitors.MongoQueryableMethodTranslatingExpressionVisitor.Visit(Expression expression)
      at MongoDB.EntityFrameworkCore.Query.Visitors.MongoQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
      at MongoDB.EntityFrameworkCore.Query.Visitors.MongoQueryableMethodTranslatingExpressionVisitor.Visit(Expression expression)
      at MongoDB.EntityFrameworkCore.Query.Visitors.MongoQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
      at MongoDB.EntityFrameworkCore.Query.Visitors.MongoQueryableMethodTranslatingExpressionVisitor.Visit(Expression expression)
      at MongoDB.EntityFrameworkCore.Query.MongoQueryCompilationContext.CreateQueryExecutor[TResult](Expression originalQuery)
      at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
      at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
      at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c_DisplayClass12_0`1.<ExecuteAsync>b_0()
      at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
      at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
      at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
      at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, Expression expression, CancellationToken cancellationToken)
      at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, CancellationToken cancellationToken)
      at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.FirstOrDefaultAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
      at Microsoft.EntityFrameworkCore.Internal.EntityFinder`1.GetDatabaseValuesAsync(InternalEntityEntry entry, CancellationToken cancellationToken)
      at Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry.GetDatabaseValuesAsync(CancellationToken cancellationToken)
      at Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry.ReloadAsync(CancellationToken cancellationToken)
      ```

            Assignee:
            damien.guard@mongodb.com Damien Guard
            Reporter:
            luiz.motta@mottacode.com Luiz Motta
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              None
              None
              None
              None