MySql EntityFrameworkCore System.TypeLoadException

I am trying to connect my web API to the 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 get a System.TypeLoadException with this description:

System.TypeLoadException: "Clone method in type 'MySQL.Data.EntityFrameworkCore.Infraestructure.Internal.MySQLOptionsExtension' from the assembly 'MySql.Data.EntityFrameworkCore, Version = 8.0.8.0, Culture = neutral, PublicKeyToken = c5697fc "

I am using Microsoft Visual Studio Community 2017 Preview (2) and my project is in .NET Core 2.0. I also use MySql.Data.EntityFrameworkCore.dll and Microsoft.AspNetCore.All (2.0.0-preview2-final). I changed librairy for MySql many times, but to no avail.

, ? ?

+5
3

, , MySql.Data.EntityFrameworkCore .Net Core 2.0 ( ). .Net Core 1.3, ... !

+7

Pomelo.EntityFrameworkCore.MySql 2.0.0. .NET Core 2.0

+4

"Pomelo.EntityFrameworkCore.MySql". Stertup.cs & appsettings.json & DbContext:

services.AddDbContext<mvccoreContext>(options =>
         options.UseMySql(Configuration.GetConnectionString("DefaultConnection")
        ));


     {
      "ConnectionStrings": {
        "DefaultConnection": "Server=localhost;Database=mvccore;User=root;Password=;"
      },
      "Logging": {
        "LogLevel": {
          "Default": "Warning"
        }
      },
      "AllowedHosts": "*"
    }


protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (!optionsBuilder.IsConfigured)
        {
            optionsBuilder.UseMySql("");
        }
    }
0

Source: https://habr.com/ru/post/1682761/


All Articles