Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySql EntityFrameworkCore System.TypeLoadException

I am trying to connect my web API to MySql database with this code:

public class Startup
{       
    public void ConfigureServices(IServiceCollection services)
    {
        string conn_string = "server=server;database=database;uid=uid;pwd=pwd;";
        MySqlConnection conn = new MySqlConnection(conn_string);
        services.AddDbContext<TaskContext>(options =>
        {
            options.UseMySQL(conn);
        });
        services.AddMvc();
    }      
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseMvc();
    }
}

But I always recieve a System.TypeLoadException with this description:

System.TypeLoadException : 'Method 'Clone' in type 'MySQL.Data.EntityFrameworkCore.Infraestructure.Internal.MySQLOptionsExtension' from assembly 'MySql.Data.EntityFrameworkCore, Version=8.0.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.'

I am using Microsoft Visual Studio Community 2017 Preview (2) and my projet is in .NET Core 2.0. I also use MySql.Data.EntityFrameworkCore.dll and Microsoft.AspNetCore.All (2.0.0-preview2-final). I have changed many times of librairy for MySql but without success.

Any idea why this always happen? What could be the cause?

like image 705
Marcel Jr. Samson Morasse Avatar asked Aug 01 '17 13:08

Marcel Jr. Samson Morasse


2 Answers

Well, it turns out that you can't use MySql.Data.EntityFrameworkCore for .Net Core 2.0(for now). I had to go back to .Net Core 1.3 to make it work... We may be able to use it in a near futur tho!

like image 174
Marcel Jr. Samson Morasse Avatar answered Sep 22 '22 19:09

Marcel Jr. Samson Morasse


Use Pomelo.EntityFrameworkCore.MySql 2.0.0. Works fine for me with .NET Core 2.0

like image 28
Anish Avatar answered Sep 22 '22 19:09

Anish