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

.net-core asp.net-core-mvc entity-framework entity-framework-core mysql

Question

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=8.0.9.0, 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>();
    optionsBuilder.UseMySQL(connectionString);

    var context = new EmployeesContext(optionsBuilder.Options);
    context.Database.EnsureCreated();

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.

EDIT

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?

1
0
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 https://github.com/jasonsturges/mysql-dotnet-core

2
10/22/2017 8:33:55 AM


Related Questions





Related

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