question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EF Core Global Query Filter problem

See original GitHub issue
  • 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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:22 (15 by maintainers)

github_iconTop GitHub Comments

8reactions
ismcagdascommented, Nov 27, 2017

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);

4reactions
hikalkancommented, Nov 28, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

Global Query Filters - EF Core
Global query filters are LINQ query predicates applied to Entity Types in the metadata model (usually in OnModelCreating ). A query predicate is ......
Read more >
Entity Framework Core: Global query filter not ...
Entity Framework Core : Global query filter not filtering correctly after data change. We implemented a soft deletion pattern with Entity ...
Read more >
Global query filters produce too many parameters #24476
If I add global query filters to all of my entities and the filters use the same property on the DbContext as a...
Read more >
Global query filters in Entity Framework Core 2.0
Entity Framework Core 2.0 introduces global query filters that can be applied to entities when model is created. It makes it easier to...
Read more >
Using EF Core Global Query Filters To Ignore Soft Deleted ...
The problem with this is that it only gives examples on how to do this for each entity, one at a time. If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found