Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The type initializer for 'Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache' threw an exception #15511

Closed
Coflys opened this issue Apr 28, 2019 · 2 comments

Comments

@Coflys
Copy link

Coflys commented Apr 28, 2019

windows server 2008 r2

Exception has been thrown by the target of an invocation.
The type initializer for 'Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache' threw an exception.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstanceT

@jonasnordlund
Copy link

jonasnordlund commented May 13, 2019

I got here via a web search as we just had the same problem. Ensure that all your NuGet package versions are up-to-date. The first install of Microsoft.EntityFrameworkCore and assorted related providers like Sqlite and PostgreSQL does surprisingly not build in a functioning state for us.

After downloading the latest versions of the NuGet packages, Visual Studio immediately wants us to update a large number of their dependencies even more. And what's more, after a first wave of updates, we have needed to close the NuGet Package Manager tab and re-open it, and even more updates are discovered as available (and actually necessary).

For us, I think the root cause of this particular one was that it needed the System.ValueTuple package (a dependency from Npgsql.EntityframeworkCore.PostgreSQL) to be no less than Version 4.5.0. You may find more information if you look into the InnerException of your exception. There's a hint in the exception in that it's one of the providers and not EF Core itself that has a problem; in our case a late-loaded assembly causing a runtime exception due to a version mismatch.

@a-einstein
Copy link

I have also been struggling a long time with errors about the version of System.ValueTuple, in the context of other changes.

I read that particular packages depends of the targeted frameworks.
Check this: Could not load file or assembly System.ValueTuple

For me solving turned out to be related to installed packages, dependencies, and version redirects.
Finding information about regeneration of the redirects finally helped me to sort it out.

Check this topic and my remark there: AutoGenerateBindingRedirects doesn't work for class libraries

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants