Ef6: EF6.3 Type initializer for MethodCallTranslator NullException

Created on 22 Oct 2019  路  6Comments  路  Source: dotnet/ef6

I don't know if this is supposed to be supported but I have a .NETCore 3 app, website, referencing a RBACRepository which targets .NET 4.7 - probably not.

Problem occurs in the here as it tries to add a null coming from StringConcatTranslator at here.

System.TypeInitializationException: The type initializer for 'MethodCallTranslator' threw an exception.
 ---> System.ArgumentNullException: Value cannot be null. (Parameter 'key')
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.InitializeMethodTranslators() in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ELinq\MethodCallTranslator.cs:line 118
   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator..cctor() in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ELinq\MethodCallTranslator.cs:line 98
   --- End of inner exception stack trace ---
   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ELinq\MethodCallTranslator.cs:line 40
   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ELinq\Translator.cs:line 62
   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ELinq\ExpressionConverter.cs:line 1016
   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert() in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ELinq\ExpressionConverter.cs:line 269
   at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ELinq\ELinqQueryState.cs:line 123
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass41_0.<GetResults>b__1() in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ObjectQuery`.cs:line 701
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ObjectContext.cs:line 3272
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass41_0.<GetResults>b__0() in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ObjectQuery`.cs:line 700
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ObjectQuery`.cs:line 699
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__31_0() in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ObjectQuery`.cs:line 568
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\LazyEnumerator`.cs:line 54
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<>c__14`1.<GetElementFunction>b__14_0(IEnumerable`1 sequence) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ELinq\ObjectQueryProvider.cs:line 241
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ELinq\ObjectQueryProvider.cs:line 217
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Core\Objects\ELinq\ObjectQueryProvider.cs:line 126
   at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\Linq\DbQueryProvider.cs:line 90
   at System.Linq.Queryable.Count[TSource](IQueryable`1 source, Expression`1 predicate)
   at System.Data.Entity.Migrations.History.HistoryRepository.QueryExists(String contextKey) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Migrations\History\HistoryRepository.cs:line 505
   at System.Data.Entity.Migrations.History.HistoryRepository.Exists(String contextKey) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Migrations\History\HistoryRepository.cs:line 459
   at System.Data.Entity.Migrations.History.HistoryRepository.GetLastModel(String& migrationId, String& productVersion, String contextKey) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Migrations\History\HistoryRepository.cs:line 148
   at System.Data.Entity.Internal.InternalContext.QueryForModel(DatabaseExistenceState existenceState) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\InternalContext.cs:line 302
   at System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(InternalContext internalContext, ModelHashCalculator modelHashCalculator, Boolean throwIfNoMetadata, DatabaseExistenceState existenceState) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\ModelCompatibilityChecker.cs:line 26
   at System.Data.Entity.Internal.InternalContext.CompatibleWithModel(Boolean throwIfNoMetadata, DatabaseExistenceState existenceState) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\InternalContext.cs:line 270
   at System.Data.Entity.Database.CompatibleWithModel(Boolean throwIfNoMetadata, DatabaseExistenceState existenceState) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Database.cs:line 230
   at System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\CreateDatabaseIfNotExists`.cs:line 46
   at System.Data.Entity.Internal.InternalContext.<>c__DisplayClass66_0`1.<CreateInitializationAction>b__0() in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\InternalContext.cs:line 578
   at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\InternalContext.cs:line 371
   at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\InternalContext.cs:line 561
   at System.Data.Entity.Internal.LazyInternalContext.<>c.<InitializeDatabase>b__58_0(InternalContext c) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\LazyInternalContext.cs:line 643
   at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\RetryAction`.cs:line 55
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\LazyInternalContext.cs:line 670
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\LazyInternalContext.cs:line 643
   at System.Data.Entity.Internal.InternalContext.Initialize() in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\InternalContext.cs:line 509
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\InternalContext.cs:line 805
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\Linq\InternalSet`.cs:line 596
   at System.Data.Entity.Internal.Linq.InternalSet`1.Include(String path) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Internal\Linq\InternalSet`.cs:line 727
   at System.Data.Entity.Infrastructure.DbQuery`1.Include(String path) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\Infrastructure\DbQuery`.cs:line 65
   at System.Data.Entity.QueryableExtensions.Include[T](IQueryable`1 source, String path) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\QueryableExtensions.cs:line 467
   at System.Data.Entity.QueryableExtensions.Include[T,TProperty](IQueryable`1 source, Expression`1 path) in C:\Users\sources\repoes\EntityFramework6\src\EntityFramework\QueryableExtensions.cs:line 591
   at MyProject.RBAC.Repository.RbacRepository.UserAsync(RBACContext context, Expression`1 predicate) in C:\Users\sources\repoes\src\MyProject.RBAC.Repository\RBACRepository.cs:line 252
   at MyProject.RBAC.Repository.RbacRepository.GetUserAsync(String identityName) in C:\Users\sources\repoes\src\MyProject.RBAC.Repository\RBACRepository.cs:line 114
   at MyProject.Service.Services.RBACService.GetUserAsync(String identityName) in C:\Users\sources\repoes\src\MyProject.Service\Services\RBACService.cs:line 71
   at MyProject.Web.Controllers.UserController.UserDetail() in C:\Users\sources\repoes\src\MyProject.WebCore\Controllers\UserController.cs:line 80
   at lambda_method(Closure , Object )
   at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Further technical details

EF version: 6.3.0

closed-question

All 6 comments

As far as I can see this is not supported and can be closed.

Any tips on migration path for my project would be welcome. The current approach will be to upgrade libraries to .NET Standard 2.1.

@hayer Yes, all libraries will need to support .NET Core 3.0 or .NET Standard 2.1.

This worked for me to resolve a very similar situation (and same error) as @hayer 's issue.

netcore3.1 console app (also works with aspnetcore 3.1).
Referenced repositories target net471 and reference EnitiyFramework 6.4.4.

If the EF 6.3+ references are "pulled in" by the net471 projects it seems they are restored by nuget targeting net471 even though the built project is netcore3.1. This produces the OP's error when using IQueriable<>.Concat().

When I reference EntityFramework 6.4.4 in the primary build project (console/web app) which is targeting netcore3.1, the nuget restore is based on netcore3.1 and nuget package libraries moved to the output are the ones compiled for that target.

In my case, I was able to avoid updating the shared projects which target net471 to netstandard2.1 so they can still be referenced by older projects which run on the .net framework.

@LucidObscurity I'm facing a similar issue. I'm struggling to pull out of your message what your solution actually was. Could you clarify it a bit? What did you actually do?

@jamsoft Have you found a solution? I am facing the same issue right now and I'm in what seems to be a dead end...

@jamsoft @tomakami If you install EntityFramework nuget version 6.4.4 into the parent project (.NETcore), it is multi-targeted to work with .NETstandard and .NETframework. Somehow the project knows how to make the core and plain old .NET versions play nice.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ErikvdBurgwal picture ErikvdBurgwal  路  6Comments

joelmdev picture joelmdev  路  5Comments

danmiser picture danmiser  路  6Comments

steamwings picture steamwings  路  7Comments

domagojmedo picture domagojmedo  路  7Comments