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?
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!
Use Pomelo.EntityFrameworkCore.MySql 2.0.0. Works fine for me with .NET Core 2.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With