dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.66k stars 3.16k forks source link

SingleOrDefaultAsync query w/ AutoMapper crash w3wp process on Azure #17617

Closed joakimriedel closed 1 year ago

joakimriedel commented 5 years ago

I'm trying to nail down a crash occurring with a particular query. The crash only occurs when running a release build on Azure App Services. Running the same query locally in Visual Studio 2019 works fine.

On Azure App Services, I've managed to create a dump file using Crash Diagnoser extension.

Exception message: 
Unhandled exception at 0x76ECB152 (KERNELBASE.dll) in w3wp_21748_RD0003FF3DBBE8.dmp: 0xE0434352 (parameters: 0x80070057, 0x00000000, 0x00000000, 0x00000000, 0x6F730000). occurred
Stack trace:
    [External Code] 
    [Managed to Native Transition]  
>   System.Linq.Expressions.dll!System.Linq.Expressions.Expression.Field(System.Linq.Expressions.Expression expression, System.Reflection.FieldInfo field) Line 143 C#
    System.Linq.Expressions.dll!System.Linq.Expressions.Expression.MakeMemberAccess(System.Linq.Expressions.Expression expression, System.Reflection.MemberInfo member) Line 391    C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ShiftMemberAccess(System.Linq.Expressions.Expression targetExpression, System.Linq.Expressions.Expression currentExpression) Line 1425    C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.IntroduceTransparentScope(Remotion.Linq.Clauses.IQuerySource querySource, Remotion.Linq.QueryModel queryModel, int index, System.Type transparentIdentifierType) Line 1392    C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitGroupJoinClause(Remotion.Linq.Clauses.GroupJoinClause groupJoinClause, Remotion.Linq.QueryModel queryModel, int index) Line 1067 C#
    Microsoft.EntityFrameworkCore.Relational.dll!Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitGroupJoinClause(Remotion.Linq.Clauses.GroupJoinClause groupJoinClause, Remotion.Linq.QueryModel queryModel, int index) Line 795   C#
    Remotion.Linq.dll!Remotion.Linq.Clauses.GroupJoinClause.Accept(Remotion.Linq.IQueryModelVisitor visitor, Remotion.Linq.QueryModel queryModel, int index)    Unknown
    Remotion.Linq.dll!Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(System.Collections.ObjectModel.ObservableCollection<Remotion.Linq.Clauses.IBodyClause> bodyClauses, Remotion.Linq.QueryModel queryModel) Unknown
    Remotion.Linq.dll!Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(Remotion.Linq.QueryModel queryModel)  Unknown
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(Remotion.Linq.QueryModel queryModel) Line 826 C#
    Microsoft.EntityFrameworkCore.Relational.dll!Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(Remotion.Linq.QueryModel queryModel) Line 397  C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateAsyncQueryExecutor<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel>(Remotion.Linq.QueryModel queryModel) Line 212 C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Storage.Database.CompileAsyncQuery<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel>(Remotion.Linq.QueryModel queryModel) Line 82  C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileAsyncQueryCore<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel>(System.Linq.Expressions.Expression query, Microsoft.EntityFrameworkCore.Query.Internal.IQueryModelGenerator queryModelGenerator, Microsoft.EntityFrameworkCore.Storage.IDatabase database) Line 274   C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileAsyncQuery.AnonymousMethod__0() Line 264    C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore<System.Collections.Generic.IAsyncEnumerable<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel>>(object cacheKey, System.Func<System.Func<Microsoft.EntityFrameworkCore.Query.QueryContext, System.Collections.Generic.IAsyncEnumerable<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel>>> compiler) Line 67   C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddAsyncQuery<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel>(object cacheKey, System.Func<System.Func<Microsoft.EntityFrameworkCore.Query.QueryContext, System.Collections.Generic.IAsyncEnumerable<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel>>> compiler) Line 52   C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileAsyncQuery<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel>(System.Linq.Expressions.Expression query) Line 261    C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel>(System.Linq.Expressions.Expression query, System.Threading.CancellationToken cancellationToken) Line 222   C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel>(System.Linq.Expressions.Expression expression, System.Threading.CancellationToken cancellationToken) Line 84 C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel, TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel>(System.Reflection.MethodInfo operatorMethodInfo, System.Linq.IQueryable<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel> source, System.Threading.CancellationToken cancellationToken) Line 2896    C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.SingleOrDefaultAsync<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel>(System.Linq.IQueryable<TrastxWebApp.Areas.Admin.Models.AdsViewModels.DetailViewModel> source, System.Threading.CancellationToken cancellationToken) Line 647 C#
    TrastxWebApp.dll!TrastxWebApp.Areas.Admin.Controllers.AdsController.Details(int? id)    Unknown
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(object target, object[] parameters) Line 108   C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultTypeMapper mapper, Microsoft.Extensions.Internal.ObjectMethodExecutor executor, object controller, object[] arguments) Line 157   C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() Line 352  C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.State next, ref Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Scope scope, ref object state, ref bool isCompleted) Line 232  C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() Line 295  C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.State next, ref Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Scope scope, ref object state, ref bool isCompleted) Line 205  C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() Line 295  C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAwaitedAsync() Line 324   C#
    Microsoft.AspNetCore.Mvc.ViewFeatures.dll!Microsoft.AspNetCore.Mvc.Controller.OnActionExecutionAsync(Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext context, Microsoft.AspNetCore.Mvc.Filters.ActionExecutionDelegate next) Line 363   C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ControllerActionFilter.OnActionExecutionAsync(Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext context, Microsoft.AspNetCore.Mvc.Filters.ActionExecutionDelegate next) Line 53   C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.State next, ref Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Scope scope, ref object state, ref bool isCompleted) Line 125  C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() Line 385   C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.State next, ref Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Scope scope, ref object state, ref bool isCompleted) Line 693  C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync() Line 817   C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.State next, ref Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Scope scope, ref object state, ref bool isCompleted) Line 578  C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() Line 793 C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.State next, ref Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Scope scope, ref object state, ref bool isCompleted) Line 417  C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() Line 123    C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() Line 81   C#
    Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Internal.MvcEndpointDataSource.CreateEndpoint.AnonymousMethod__0(Microsoft.AspNetCore.Http.HttpContext context) Line 560 C#
    Microsoft.AspNetCore.Routing.dll!Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext httpContext) Line 42  C#
    Microsoft.AspNetCore.Routing.dll!Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext httpContext) Line 78   C#
    Microsoft.AspNetCore.Http.Abstractions.dll!Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context) Line 74  C#
    Microsoft.AspNetCore.CookiePolicy.dll!Microsoft.AspNetCore.CookiePolicy.CookiePolicyMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context) Line 43    C#
    Microsoft.AspNetCore.StaticFiles.dll!Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context) Line 139   C#
    Microsoft.AspNetCore.Diagnostics.dll!Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context) Line 32   C#
    Microsoft.AspNetCore.Http.Abstractions.dll!Microsoft.AspNetCore.Builder.UseWhenExtensions.UseWhen.AnonymousMethod__1(Microsoft.AspNetCore.Http.HttpContext context) Line 61 C#
    Microsoft.AspNetCore.HttpsPolicy.dll!Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context) Line 103 C#
    Microsoft.AspNetCore.HttpsPolicy.dll!Microsoft.AspNetCore.HttpsPolicy.HstsMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context) Line 87  C#
    Microsoft.AspNetCore.Diagnostics.dll!Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context) Line 52  C#
    Microsoft.AspNetCore.Localization.dll!Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context) Line 136    C#
    [Resuming Async Method] 
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.<Invoke>d__5>..cctor.AnonymousMethod__9_0(object s) Line 525  C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 167  C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.<Invoke>d__5>.MoveNext() Line 559 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) Line 798 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3258    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.__Canon>.TrySetResult(System.__Canon result) Line 421 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.AspNetCore.Localization.ProviderCultureResult>.SetExistingTaskResult(Microsoft.AspNetCore.Localization.ProviderCultureResult result) Line 639   C#
    TrastxWebApp.dll!TrastxWebApp.Services.ApplicationUserRequestCultureProvider.DetermineProviderCultureResult(Microsoft.AspNetCore.Http.HttpContext httpContext)  Unknown
    [Resuming Async Method] 
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.AspNetCore.Localization.ProviderCultureResult>.AsyncStateMachineBox<TrastxWebApp.Services.ApplicationUserRequestCultureProvider.<DetermineProviderCultureResult>d__0>..cctor.AnonymousMethod__9_0(object s) Line 525    C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 167  C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.AspNetCore.Localization.ProviderCultureResult>.AsyncStateMachineBox<TrastxWebApp.Services.ApplicationUserRequestCultureProvider.<DetermineProviderCultureResult>d__0>.MoveNext() Line 559   C#
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) Line 798 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3258    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.__Canon>.TrySetResult(System.__Canon result) Line 421 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.SetExistingTaskResult(string result) Line 639 C#
    TrastxWebApp.dll!TrastxWebApp.Services.CurrentRequest.GetCultureAsync() Unknown
    [Resuming Async Method] 
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.AsyncStateMachineBox<TrastxWebApp.Services.CurrentRequest.<GetCultureAsync>d__10>..cctor.AnonymousMethod__9_0(object s) Line 525  C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 167  C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.AsyncStateMachineBox<TrastxWebApp.Services.CurrentRequest.<GetCultureAsync>d__10>.MoveNext() Line 559 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) Line 798 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3258    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.__Canon>.TrySetResult(System.__Canon result) Line 421 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.SetExistingTaskResult(string result) Line 639 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.SetResult(string result) Line 629 C#
    [External Code] 
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.AsyncStateMachineBox<LazyCache.CachingService.<GetOrAddAsync>d__24<string>>..cctor.AnonymousMethod__9_0(object s) Line 525    C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 167  C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.AsyncStateMachineBox<LazyCache.CachingService.<GetOrAddAsync>d__24<string>>.MoveNext() Line 559   C#
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) Line 798 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3258    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.__Canon>.TrySetResult(System.__Canon result) Line 421 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.UnwrapPromise<string>.TrySetFromTask(System.Threading.Tasks.Task task, bool lookForOce) Line 6607 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.UnwrapPromise<string>.InvokeCore(System.Threading.Tasks.Task completingTask) Line 6509    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.UnwrapPromise<System.__Canon>.Invoke(System.Threading.Tasks.Task completingTask) Line 6492    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunOrQueueCompletionAction(System.Threading.Tasks.ITaskCompletionAction completionAction, bool allowInlining) Line 3358  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3276    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.__Canon>.TrySetResult(System.__Canon result) Line 421 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.SetExistingTaskResult(string result) Line 639 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.SetResult(string result) Line 629 C#
    [External Code] 
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<ExecuteSingletonAsyncQuery>d__21<string>>..cctor.AnonymousMethod__9_0(object s) Line 525 C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 167  C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<ExecuteSingletonAsyncQuery>d__21<string>>.MoveNext() Line 559    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) Line 798 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3258    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<bool>.TrySetResult(bool result) Line 421 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.SetExistingTaskResult(bool result) Line 639 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.SetResult(bool result) Line 629 C#
    [External Code] 
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor<string>.EnumeratorExceptionInterceptor.<MoveNext>d__5>..cctor.AnonymousMethod__9_0(object s) Line 525  C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 167  C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor<string>.EnumeratorExceptionInterceptor.<MoveNext>d__5>.MoveNext() Line 559 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) Line 798 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3258    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<bool>.TrySetResult(bool result) Line 421 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.SetExistingTaskResult(bool result) Line 639 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.SetResult(bool result) Line 629 C#
    [External Code] 
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.TaskResultAsyncEnumerable<string>.Enumerator.<MoveNext>d__3>..cctor.AnonymousMethod__9_0(object s) Line 525 C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 167  C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.TaskResultAsyncEnumerable<string>.Enumerator.<MoveNext>d__3>.MoveNext() Line 559    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) Line 798 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3258    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.__Canon>.TrySetResult(System.__Canon result) Line 421 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.SetExistingTaskResult(string result) Line 639 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.SetResult(string result) Line 629 C#
    [External Code] 
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.AsyncStateMachineBox<System.Linq.AsyncEnumerable.<Single_>d__380<string>>..cctor.AnonymousMethod__9_0(object s) Line 525  C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 167  C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<string>.AsyncStateMachineBox<System.Linq.AsyncEnumerable.<Single_>d__380<string>>.MoveNext() Line 559 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) Line 798 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3258    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<bool>.TrySetResult(bool result) Line 421 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.SetExistingTaskResult(bool result) Line 639 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.SetResult(bool result) Line 629 C#
    [External Code] 
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable<string>.AsyncEnumerator.<MoveNext>d__11>..cctor.AnonymousMethod__9_0(object s) Line 525   C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 167  C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable<string>.AsyncEnumerator.<MoveNext>d__11>.MoveNext() Line 559  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) Line 798 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3258    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<bool>.TrySetResult(bool result) Line 421 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.SetExistingTaskResult(bool result) Line 639 C#
    Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync<bool, bool>(System.Func<Microsoft.EntityFrameworkCore.DbContext, bool, System.Threading.CancellationToken, System.Threading.Tasks.Task<bool>> operation, System.Func<Microsoft.EntityFrameworkCore.DbContext, bool, System.Threading.CancellationToken, System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.Storage.ExecutionResult<bool>>> verifySucceeded, bool state, System.Threading.CancellationToken cancellationToken) Line 305  C#
    [Resuming Async Method] 
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<ExecuteImplementationAsync>d__31<bool, bool>>..cctor.AnonymousMethod__9_0(object s) Line 525  C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 167  C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<ExecuteImplementationAsync>d__31<bool, bool>>.MoveNext() Line 559 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) Line 798 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3258    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<bool>.TrySetResult(bool result) Line 421 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.SetExistingTaskResult(bool result) Line 639 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.SetResult(bool result) Line 629 C#
    [External Code] 
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable<string>.AsyncEnumerator.<BufferlessMoveNext>d__12>..cctor.AnonymousMethod__9_0(object s) Line 525 C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 167  C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable<string>.AsyncEnumerator.<BufferlessMoveNext>d__12>.MoveNext() Line 559    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) Line 798 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3258    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.__Canon>.TrySetResult(System.__Canon result) Line 421 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.TaskCompletionSource<System.__Canon>.TrySetResult(System.__Canon result) Line 274 C#
    Microsoft.EntityFrameworkCore.Relational.dll!System.Threading.Tasks.RelationalTaskExtensions.Cast.AnonymousMethod__0(System.Threading.Tasks.Task<object> t) Line 29 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.ContinuationTaskFromResultTask<object>.InnerInvoke() Line 163 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task..cctor.AnonymousMethod__275_1(object obj) Line 2461  C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 167  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) Line 2421    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteEntryUnsafe() Line 2365   C#
    System.Private.CoreLib.dll!System.Threading.Tasks.ThreadPoolTaskScheduler.TryExecuteTaskInline(System.Threading.Tasks.Task task, bool taskWasPreviouslyQueued) Line 75  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.TaskScheduler.TryRunInline(System.Threading.Tasks.Task task, bool taskWasPreviouslyQueued) Line 210   C#
    System.Private.CoreLib.dll!System.Threading.Tasks.TaskContinuation.InlineIfPossibleOrElseQueue(System.Threading.Tasks.Task task, bool needsProtection) Line 255 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.StandardTaskContinuation.Run(System.Threading.Tasks.Task completedTask, bool bCanInlineContinuationTask) Line 362 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3270    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.__Canon>.TrySetResult(System.__Canon result) Line 421 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object>.SetExistingTaskResult(object result) Line 639 C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object>.SetResult(object result) Line 629 C#
    [External Code] 
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.<ExecuteAsync>d__17>..cctor.AnonymousMethod__9_0(object s) Line 525 C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 167  C#
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object>.AsyncStateMachineBox<Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.<ExecuteAsync>d__17>.MoveNext() Line 559    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) Line 798 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3258    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishStageThree() Line 2174 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishStageTwo() Line 2149   C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishSlow(bool userDelegateExecute) Line 2044   C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) Line 2440    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteEntryUnsafe() Line 2365   C#
    System.Private.CoreLib.dll!System.Threading.Tasks.ThreadPoolTaskScheduler.TryExecuteTaskInline(System.Threading.Tasks.Task task, bool taskWasPreviouslyQueued) Line 75  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.TaskScheduler.TryRunInline(System.Threading.Tasks.Task task, bool taskWasPreviouslyQueued) Line 210   C#
    System.Private.CoreLib.dll!System.Threading.Tasks.TaskContinuation.InlineIfPossibleOrElseQueue(System.Threading.Tasks.Task task, bool needsProtection) Line 255 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.StandardTaskContinuation.Run(System.Threading.Tasks.Task completedTask, bool bCanInlineContinuationTask) Line 362 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3270    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.__Canon>.TrySetResult(System.__Canon result) Line 421 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.UnwrapPromise<System.Data.SqlClient.SqlDataReader>.TrySetFromTask(System.Threading.Tasks.Task task, bool lookForOce) Line 6607    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.UnwrapPromise<System.__Canon>.ProcessInnerTask(System.Threading.Tasks.Task task) Line 6631    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.UnwrapPromise<System.Data.SqlClient.SqlDataReader>.ProcessCompletedOuterTask(System.Threading.Tasks.Task task) Line 6560  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.UnwrapPromise<System.__Canon>.InvokeCore(System.Threading.Tasks.Task completingTask) Line 6516    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.UnwrapPromise<System.__Canon>.Invoke(System.Threading.Tasks.Task completingTask) Line 6492    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunOrQueueCompletionAction(System.Threading.Tasks.ITaskCompletionAction completionAction, bool allowInlining) Line 3358  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3276    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3228  C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishStageThree() Line 2174 C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishStageTwo() Line 2149   C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishSlow(bool userDelegateExecute) Line 2044   C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) Line 2440    C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteEntryUnsafe() Line 2365   C#
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() Line 2305 C#
    System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() Line 588 C#
    System.Private.CoreLib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() Line 879  C#
    [Native to Managed Transition]  
    [External Code] 

Steps to reproduce

I'm unable to create a small reproducible example. The query itself is quite simple, a standard AutoMapper projection. The actual query itself has been in production on the same server for several months, even though we just deployed a new version of the application using additional database columns that do affect the projected entities and the actual SQL generated.

var ad = await _context.Ads
                .Where(a => a.Id == id)
                .ProjectTo<DetailViewModel>(_configurationProvider)
                .SingleOrDefaultAsync();

I can provide the dump file, for size (280MB) and security reasons let me know where I can send it for further debugging.

Further technical details

EF Core version: 2.2.6 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Azure App Services IDE: Visual Studio 2019 16.2.3

smitpatel commented 5 years ago

The code from stacktrace no longer exist in EF Core 3.0. Please try 3.0 preview package (preview9 from nuget or daily build).

joakimriedel commented 5 years ago

@smitpatel @ajcvickers I've tried migrating to 3.0 previews earlier, but it seems so unstable that I've tried to postpone application migration until RTM. But to assist finding this bug, I made another attempt at migrating - now to the latest preview9 as you mention. However, I can't even get my tests to pass to get it through our build pipelines. 😣

I've tried to follow all available migration guides and blog posts. Still, a simple;

Assert.Equal(1, _dbContext.Ads.Count());
ad = await _dbContext.Ads.SingleAsync();

Renders this exception for the InMemory db. Note that the Ads.Count() returns 1 as expected by this particular test.

System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
     at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.EntityProjectionExpression.BindProperty(IProperty property)
     at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryExpressionTranslatingExpressionVisitor.BindProperty(EntityProjectionExpression entityProjectionExpression, IProperty property)
     at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryExpressionTranslatingExpressionVisitor.BindProperty(Expression source, String propertyName, Type type)
     at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryExpressionTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
     at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
     at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
     at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryExpressionTranslatingExpressionVisitor.Translate(Expression expression)
     at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryProjectionBindingExpressionVisitor.Visit(Expression expression)
     at Microsoft.EntityFrameworkCore.Query.IncludeExpression.VisitChildren(ExpressionVisitor visitor)
     at System.Linq.Expressions.ExpressionVisitor.VisitExtension(Expression node)
     at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryProjectionBindingExpressionVisitor.VisitExtension(Expression extensionExpression)
     at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
     at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
     at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryProjectionBindingExpressionVisitor.Visit(Expression expression)
     at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryProjectionBindingExpressionVisitor.Translate(InMemoryQueryExpression queryExpression, Expression expression)
     at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryQueryableMethodTranslatingExpressionVisitor.TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)
     at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
     at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
     at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
     at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
     at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
     at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
     at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
     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.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
     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.SingleAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)

How can I make my tests pass using 3.0 preview 9 ? Everything works a charm in 2.2.6.

smitpatel commented 5 years ago

If you are using any provider other than InMemory then preview9 should work. If you are using InMemory provider then use daily builds. It will not be too much difficult if you have migrated to preview9 already. (Just setting up few feeds and restoring package). InMemory query work went in couple of days ago.

joakimriedel commented 5 years ago

@smitpatel OK, now with daily builds (3.0.0-rc1.19455.5) this particular test is running fine.

Unfortunately I still have about 55 failing tests to solve before I'm able to build a release version and put on Azure to find out if the crash mentioned above for this issue is still present. Most of my failing tests seem to depend on queries using advanced expressions. We've been building this project over two years time and have a lot of heavy expression queries against EF Core. It's been challenging to make everything work, but they do all run fine with 2.2.6.

Please look at the following gist (uncomment package references so that you use the daily builds):

https://gist.github.com/jcemoller/312a2aaa3c27ec18318881619439e867

This particular way of building expressions does not work in Ef Core 3.0, not even the daily builds. I've tried with both SqlServer and InMemory provider, but to no success.

This is the exception I get:

System.InvalidOperationException
  HResult=0x80131509
  Message=EF.Property called with wrong property name.
  Source=Microsoft.EntityFrameworkCore.Relational
  StackTrace:
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.VisitBinary(BinaryExpression binaryExpression)
   at Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerSqlTranslatingExpressionVisitor.VisitBinary(BinaryExpression binaryExpression)
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.Translate(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateExpression(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateLambdaExpression(ShapedQueryExpression shapedQueryExpression, LambdaExpression lambdaExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.TranslateSubquery(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.Translate(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateExpression(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateLambdaExpression(ShapedQueryExpression shapedQueryExpression, LambdaExpression lambdaExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
   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.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
   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.CountAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at EfCoreBugExpression.Program.<Main>d__1.MoveNext() in C:\Users\Joakim\Source\Repos\EfCoreBug\EFCoreBugExpression\Program.cs:line 30
joakimriedel commented 5 years ago

@ajcvickers @smitpatel I'm sorry but we cannot wait for 3.1, we need to push a new release up asap. What's our options now?

Our application based on 2.2.6 has recently started crashing the w3wp process, possibly due to StackOverflowException, probably due to large entity graphs. Your suggestion is to upgrade to daily builds of 3.0, but due to the mentioned regression where interfaces are not supported in expressions, we cannot even produce a release build to see if the crash is resolved in 3.0.

smitpatel commented 5 years ago

cc: @divega

joakimriedel commented 5 years ago

@smitpatel due to the regressions in 3.0 when using expressions in queries, I spent the last 10 hours inlining all generic or interface-based expressions directly into the queries in a couple of hundred places. I'm not a fan of code duplication, but still, I managed at last to make the project build and run.

On the positive side:

On the negative side:

Why are we dependent on using expressions using interfaces? For example, we have some entities that do not relate to each other but they all have a navigation collection Verifications. Previously, in 2.2.6 and earlier, I could have a generic expression based on IVerifiable that I'd tack on all entities having the Verifications collection. I could then use a generic form of IsVerified expression based on the IVerifiable interface. Now with 3.0, due to the regression mentioned above and not using generics, I have to duplicate the expression so that I have EntityAIsVerified, EntitiyBIsVerified etc.

Also, on a side note. Previously using AutoMapper I did not have to use .AsNoTracking(). With 3.0 I have to add .AsNoTracking() on all AutoMapper queries otherwise I get this error message:

InvalidOperationException: A tracking query projects owned entity without corresponding owner in result. Owned entities cannot be tracked without their owner. Either include the owner entity in the result or make query non-tracking using AsNoTracking().

Lastly, sorry if I've been a bit hard on the tone in this issue but I'm on a tight deadline and should have had a new release out this week. Instead I've spent four days intensively on this issue. I guess you are also under pressure now that 3.0 is closing in on release, and you're doing a great job maintaining this project.

divega commented 5 years ago

@jcemoller glad to hear that you have a workaround. Hopefully you will be able to simplify your code again when we address this limitation in 3.1.

Re owned entities projected without their owner requiring AsNoTracking, last time we discussed this we came to the conclusion that switching the behavior of the query to non-tracking automatically could be too unexpected, given that the design is that owned entities are trackable objects but need to be accompanied by their owner. The other option was to auto-include the owner to be able honor tracking, but that would mean bringing more data from the database than you explicitly asked for in the query. Yet another option would be to change some of the invariants in the design and allow “free” owned entities to be tracked accompanied just with the key value of the owner.

We are open to feedback on this area (as with more things). If you have an opinion on how we should change the design, feel free to create an issue specifically for this.

joakimriedel commented 5 years ago

@divega I agree that switching a supposedly tracking query to non-tracking automatically would be unexpected, but up to 3.0 all queries which do a .Select(x => new Y(x)) to project into client entities was automatically non-tracking. This is a big breaking change, since I have to find all these places and add .AsNoTracking to prevent a runtime failure. It is not documented in https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes.

joakimriedel commented 5 years ago

@smitpatel @divega So, week later and I'm still investigating this issue. Turned out, that after all work migrating to 3.0 and getting our application running again, I now face major performance issues on this very same query. This query, even though it's pretty complex, used to run in a few seconds. In 2.2, after adding an additional column to an entity as reported originally for this issue, I started to get stack overflow exceptions and it crashed the entire process. In 3.0, the query now works again but very slow.

I originally thought I was having SQL Server issues (see https://github.com/aspnet/EntityFrameworkCore/issues/17743) but after updating statistics using sp_updatestats I have gotten the SQL query back to run in about 1 second. This has been verified by running;

1) Performance Profiler in Visual Studio 2019, reporting the query execution time 2) SQL Server Profiler 3) Copy-pasting the query into SQL Management Studio and running it manually

Running the actual application however, it now takes more than 1 minute to get the results back from the SingleOrDefaultAsync() method call. From investigations, it seems actually as if most of the delta between method execution time and SQL query time is spent before the actual query is sent to the SQL Server. Perhaps in some kind of query/expression tree parsing gone wild?

Performance Profiler session

This is the query execution time reported;

image

This is the CPU spent in the method;

image

As you can see, 62% of the CPU in the entire session of loading an ASP.NET MVC page is spent in the SingleOrDefaultAsync() method!

Unfortunately I cannot see further down in the call tree because I do not have the required symbols.

Symbols failed to load for Microsoft.EntityFrameworkCore.dll. Cannot find or open the PDB file.

Is this because I am running daily builds? How can I get the necessary PDB files for the daily builds?

joakimriedel commented 5 years ago

Note: Cleaned up this case by moving the unrelated expression regressions in 3.0 into separate issues.

joakimriedel commented 5 years ago

@smitpatel @divega somehow I was still on 3.0.0-rc1 branch 😫 switched to 3.0.0-rc2 and the slowdown is gone. Guess this is what happens when you're new to having to work on daily builds.

Would still like to know how to access the PDB files for daily builds though.

Closing this case for now.

smitpatel commented 5 years ago

Re-opening to fix issue mentioned in https://github.com/aspnet/EntityFrameworkCore/issues/17617#issuecomment-528514335

For regression, we made a fix in daily builds last week only.

smitpatel commented 5 years ago

I see #17794 covers this scenario. Closing this as dupe.