简体   繁体   中英

MissingMethodException: Method not found: 'Boolean Microsoft.EntityFrameworkCore.Migrations.IMigrationsModelDiffer.HasDifferences()

I am using MySql database with ASP.NET Core MVC application (version: .Net Core 3.1).
startup.cs class has auto-generated code:

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
    app.UseDatabaseErrorPage(); // commenting this not showing exception page.
}

Here, if I remove the code: app.UseDatabaseErrorPage() it does not shows exception on running the program. I am not sure is needed for the program or not? Should I leave it commented? Or I should use it in code and solve the problem which might raising the exception.

On running the application - the page shows exception:

An unhandled exception occurred while processing the request. MissingMethodException: Method not found: 'Boolean Microsoft.EntityFrameworkCore.Migrations.IMigrationsModelDiffer.HasDifferences(Microsoft.EntityFrameworkCore.Metadata.IModel, Microsoft.EntityFrameworkCore.Metadata.IModel)'. Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)

I tried by checking:

  • NuGet packages and they are all same version 5.0.17 (because that is the most recent supporting version for .NET 3.1)

  • I have MySql connect /.NET installed.

  • I am not sure this is the cause of problem: I have this code in DbContext class (class is partial): partial void OnModelCreatingPartial(ModelBuilder modelBuilder);

From Database error page we can see:

Database Error Page Middleware captures database-related exceptions that can be resolved by using Entity Framework migrations.

You can use it in code and solve the problem which might raising the exception.

NuGet packages and they are all same version 5.0.17

Because your ASP.NET Core MVC application (version: .Net Core 3.1), I suggest you make sure all of your EF packages were pointing at the same 3.1.X version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM