Type Load Exception in EF Core Project
Solution 1
Please update to your entity framework core nuget package to 3.1.10(or latest 5.0.0). It will solve your problem.
Solution 2
I had EF Core 5 package installed, but not Microsoft.EntityFrameworkCore.Design
and one package were implicitly referencing older version (Microsoft.EntityFrameworkCore.Design 3.0.0
).
Installing explicit dependency on Microsoft.EntityFrameworkCore.Design 5.x.x
resolved the issue for me.
Solution 3
I had this issue in a .NET Core 3.1 project. I fixed it by installing the package Microsoft.EntityFrameworkCore.Design in the startup project
Solution 4
Make sure that each project referenced pulls in the same major/minor version of the Entity Framework nuget package.
I upgraded a project from V3 to V6 and didn't upgrade the EF Core nuget packages to 6. One project had 6 while the other had 3 and was receiving this error when I did an update-database
.
Solution 5
I had a similar issue when all the dependencies seemed correct in my project. But the issue was that the context was in one project in the solution and a different project in the solution was the start-up project. And that project happened to include a different version of EFCore.
Using the context's project as the start-up project in the Package Manager Console resolved the issue for me.
add-migration -startupproject myProjectWithTheMigration
Steve
Steve Ngai completed his Higher Diploma in Software Engineering in APU University and earned his Computing degree (with Honours) from the University of Staffordshire. Started out as in-house programmer and developed Inventory system, E-Leave system, Sales Order system, Job Recruitment system. Then shifted to do application support for Cheque Clearing system for central banks (Bank Negara) and some banks. Next few years he gave training software engineering courses at growing vocational school which heavily focus on hands-on coding. Now, he works full-time as software engineer (80% back-end, 20% front-end) in an investment bank using modern technologies. He writes clean and maintainable codes consistently and loves to solve complex problems with 'simple' solution.
Updated on February 03, 2022Comments
-
Steve about 2 years
I have an ASP.NET Core 3.1 Web API application using EF Core. This is the my configuration in the
ConfigureServices
method of theStartup
class:services.AddDbContext<ApplicationContext>(options => options.UseSqlServer(Configuration.GetConnectionString("AppConn")));
The above configuration tested and works for a SQL Server database.
Then I switched to using Sqlite after installing its package successfully.
services.AddDbContext<ApplicationContext>(options => options.UseSqlite("Data Source=sqlitedemo.db"));
But when I try to add the EF migration
add-migration initial -context ApplicationContext
I get this error:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer' from assembly 'Microsoft.EntityFrameworkCore, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
{ Stack trace }
Exception has been thrown by the target of an invocation.
-
Ivan Stoev over 3 yearsYou seem to have EF Core related package versions mismatch. Please include the EF Core related project package references (all entries from .csproj staring with
<PackageReference Include="Microsoft.EntityFrameworkCore.
)
-
-
Thomas over 3 years
error: There are no versions available for the package 'Microsoft.EntityFramework.Core
-
Thomas over 3 years
error: There are no versions available for the package 'Microsoft.EntityFramework.Core.Design
-
Marin about 3 yearsThe issue is which Microsoft.EntityFrameworkCore.Design did you install?
-
Pavel Biryukov about 3 yearsI have netcoreapp3.1 application with EF5 <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.5" />
-
Valter Ekholm almost 3 yearsI was helped by this answer, but have an experience to share, the version of Microsoft.EntityFrameworkCore.Tools suddenly jumped back from 5x to 3x after having deleted all migrations and trying adding "first" migration. Also, check the .csproj file.
-
Matthieu Charbonnier about 2 yearsAwesome, thanks.
-
KingNOB about 2 yearsThis solved my problem