【发布时间】:2018-01-08 10:23:15
【问题描述】:
我正在尝试使用以下代码将我的 Web API 连接到 MySql 数据库:
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();
}
}
但我总是收到带有此描述的 System.TypeLoadException:
System.TypeLoadException:类型中的“方法“克隆” 'MySQL.Data.EntityFrameworkCore.Infraestructure.Internal.MySQLOptionsExtension' 从程序集'MySql.Data.EntityFrameworkCore,版本= 8.0.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' 没有 实施。'
我正在使用 Microsoft Visual Studio Community 2017 Preview (2),并且我的项目在 .NET Core 2.0 中。我还使用 MySql.Data.EntityFrameworkCore.dll 和 Microsoft.AspNetCore.All (2.0.0-preview2-final)。我已经为 MySql 更改了很多次库,但没有成功。
知道为什么这总是发生吗?可能是什么原因?
【问题讨论】:
标签: mysql entity-framework-core asp.net-core-webapi asp.net-core-2.0