[英]Why do I still need the MySQL Connector installed on the computer despite having the proper NuGet packages?
I've got a C# ASP.NET MVC project using MariaDB with Entity Framework 6. 我有一个使用MariaDB和Entity Framework 6的C#ASP.NET MVC项目。
This project is made in Visual Studio 2017 and it took me some long hours double-checking whether I had the proper MySQL connector's assembly references added as they should, in the form of NuGet packages MySql.Data 8.0.13 and MySql.Data.EntityFramework 8.0.13 (both oficially published by Oracle), because I was getting the following error when browsing Views while debugging: 这个项目是在Visual Studio 2017中完成的,我花了很长时间仔细检查我是否以NuGet包MySql.Data 8.0.13和MySql.Data.EntityFramework的形式适当添加了正确的MySQL连接器的程序集引用。 8.0.13 (均为oficially由Oracle出版),因为我在浏览美景,一边调试时收到以下错误:
The ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is either not registered in the machine or application config file.
具有不变名称'MySql.Data.MySqlClient'的ADO.NET提供程序未在计算机或应用程序配置文件中注册。
Until I gave up on it and tried installing the MySQL Connector/NET 8.0 , after which it worked. 直到我放弃了它,并试图安装的MySQL连接器/ NET 8.0 ,在这之后的工作。 No changes made to the
web.config
file other than those performed by NuGet. 除了由NuGet执行的更改外,没有对
web.config
文件进行任何更改。
I checked the assemblies placed under %ProgramFiles%\\MySql\\Connector
by the installer, and they are bit-identical to those pulled by NuGet. 我检查了安装程序放置在
%ProgramFiles%\\MySql\\Connector
下的程序集,它们与NuGet提取的程序集完全相同。 Heck, I even deleted the entire folder, and it still worked . 哎呀, 我什至删除了整个文件夹,它仍然有效 。
What gives? 是什么赋予了? Are the NuGet packages missing some step they should perform?
NuGet软件包是否缺少应执行的某些步骤?
I suspect that the Connector/NET 8.0 installer modifies your C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\config\\machine.config
file, which is shared by all .NET applications on the machine. 我怀疑Connector / NET 8.0安装程序会修改您的
C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\config\\machine.config
文件,该文件由计算机上的所有.NET应用程序共享。 Unfortunately, this is a local change on your machine, which means that your application may not work properly when deployed. 不幸的是,这是计算机上的本地更改,这意味着您的应用程序在部署后可能无法正常运行。
The solution is to add MySql.Data to your app.config
(or Web.config
) file. 解决方案是将MySql.Data添加到您的
app.config
(或Web.config
)文件中。 I'm not sure if the NuGet packages are designed to do this automatically or not. 我不确定NuGet软件包是否旨在自动执行此操作。
Per the Oracle docs , add this information to app.config
: 根据Oracle文档 ,将此信息添加到
app.config
:
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=8.0.13.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.