aspnetboilerplate: EF Core Global Query Filter problem

  • Abp 3.1.2/3.2.4
  • framework: .Net Core.
  • WARN 2017-11-27 16:39:54,973 [18 ] Abp.Auditing.SimpleLogAuditingStore - AUDIT LOG: MyCode.Workflow.Application.InstanceAppService.GetPendingWorkItems is executed by user 1 in 395390 ms from ::1 IP address with exception: variable ‘context’ of type ‘Abp.EntityFrameworkCore.AbpDbContext’ referenced from scope ‘’, but it is not defined. ERROR 2017-11-27 16:39:54,980 [18 ] Mvc.ExceptionHandling.AbpExceptionFilter - variable ‘context’ of type ‘Abp.EntityFrameworkCore.AbpDbContext’ referenced from scope ‘’, but it is not defined System.InvalidOperationException: variable ‘context’ of type ‘Abp.EntityFrameworkCore.AbpDbContext’ referenced from scope ‘’, but it is not defined at System.Linq.Expressions.Compiler.VariableBinder.Reference(ParameterExpression node, VariableStorageKind storage) at System.Linq.Expressions.Compiler.VariableBinder.VisitParameter(ParameterExpression node) at System.Linq.Expressions.ParameterExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node) at System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node) at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node) at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection1 nodes) at System.Linq.Expressions.Compiler.VariableBinder.VisitInvocation(InvocationExpression node) at System.Linq.Expressions.InvocationExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node) at System.Linq.Expressions.Compiler.VariableBinder.VisitUnary(UnaryExpression node) at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node) at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes) at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node) at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection1 nodes) at System.Linq.Expressions.Compiler.VariableBinder.VisitLambda[T](Expression1 node) at System.Linq.Expressions.Expression1.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node) at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda) at System.Linq.Expressions.Expression1.Compile(Boolean preferInterpretation) at System.Linq.Expressions.Expression1.Compile() at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateExecutorLambdaTResults at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, INodeTypeProvider nodeTypeProvider, IDatabase database, IDiagnosticsLogger1 logger, Type contextType) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass15_01.<Execute>b__0() at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) at System.Linq.Queryable.Count[TSource](IQueryable1 source) at MyCode.Workflow.Core.Service.WorkflowInstanceManager.<>c__DisplayClass38_0.<FilterAndFillingDtosAsync>b__0() in D:*\Service\WorkflowInstanceManager_WorkList.cs:line 105 at System.Threading.Tasks.Task1.InnerInvoke() at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at MyCode.Workflow.Core.Service.WorkflowInstanceManager.<FilterAndFillingDtosAsync>d__38.MoveNext() in D:*\Service\WorkflowInstanceManager_WorkList.cs:line 105 — End of stack trace from previous location where exception was thrown — at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at MyCode.Workflow.Core.Service.WorkflowInstanceManager.<GetPendingWorkList>d__39.MoveNext() in D:\****\Service\WorkflowInstanceManager_WorkList.cs:line 129 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at MyCode.Workflow.Application.InstanceAppService.<GetPendingWorkItems>d__23.MoveNext() in D:****\Application\InstanceAppService.cs:line 361 — End of stack trace from previous location where exception was thrown — at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at lambda_method(Closure , Object ) at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextExceptionFilterAsync>d__23.MoveNext()

My web project has some data that needs to be loaded as soon as I log in, as I wrote in the code below, but this causes concurrency problems when the app is first started, with the exception above the Error stack. I tried many times, no matter what request, even if not the same table, or the same dbcontext, may have the above problems, when I refresh the page, or log off again to log in, will not appear again, just in the application from Stop until the start state will be reproduced.When I changed the code to wait for Promise to finish, the above problem did not occur, but that was not what I wanted.

My js code :Home/Index.js

(function () {
    $(function () {
        var wfService = abp.services.wf.instance;
        wfService.getPendingWorkItems({}).done(function(result) {
            $('#wfPendingCount').html(result.totalCount);
        });
        wfService.getInTrayWorkItems({}).done(function (result) {
            $('#wfInTrayCount').html(result.totalCount);
        });
        wfService.getOutTrayWorkItems({}).done(function (result) {
            $('#wfOutTrayCount').html(result.totalCount);
        });
    });
})();

Forgive my dross English, I use Google Translate to try to make my description accurate.Thank you for your time.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 22 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Hi @hemiaoio can you reproduce this problem every time you run the same code ? We are dealing with a similar issue and found a temporary workaround.

Can you try to add below line into PreInitialize method of your Core module ? AppContext.SetSwitch("Microsoft.EntityFrameworkCore.Issue9825", true);

Hi all.

It seems like this problem is fixed on EF Core 2.1 according to our tests. We must update EF Core and test with the new version when it is released.