Works on console project but not on ASP.NET project EF Core with MySql Connector

.net-core entity-framework entity-framework-core mysql


I have a weird problem here. I'm trying to access a MySql database with Entity Framework Core.

It works on the .NET console. but when the same code runs on the web app it says.

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0]
      An unhandled exception has occurred while executing the request
System.TypeLoadException: Method 'Clone' in type 'MySQL.Data.EntityFrameworkCore.Infraestructure.Internal.MySQLOptionsExtension' from assembly 'MySql.Data.EntityFrameworkCore, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.

   at Microsoft.EntityFrameworkCore.MySQLDbContextOptionsExtensions.UseMySQL[TContext]
   at ConsoleApplication.EmployeesContextFactory.Create(String connectionString) in BooksController.cs:line 65

Here is my code

    var optionsBuilder = new DbContextOptionsBuilder<EmployeesContext>();

    var context = new EmployeesContext(optionsBuilder.Options);

It gives me the exception on the method UseMySql() The same exact code works fine in the console.

Also connectionString, .NET Core version and many of the constraints that I can think of are the same.


Seeing the difference The ASP.NET project has following Nugets enter image description here

The console app has the following,

enter image description here

Both projects show it's target framework as 2.0

What's the right way to solve this issue?

10/22/2017 7:13:31 AM

Accepted Answer

Because the current MySQL connector only supports .NET Core 1, you might not be able to use it with v2.
You could try this package at

10/22/2017 8:33:55 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow