I've got a C# ASP.NET MVC project using MariaDB with Entity Framework 6.
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:
The ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is either not registered in the machine or application config file.
Until I gave up on it and tried installing the MySQL Connector/NET 8.0 , after which it worked. No changes made to the web.config
file other than those performed by NuGet.
I checked the assemblies placed under %ProgramFiles%\\MySql\\Connector
by the installer, and they are bit-identical to those pulled by NuGet. Heck, I even deleted the entire folder, and it still worked .
What gives? Are the NuGet packages missing some step they should perform?
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. 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. I'm not sure if the NuGet packages are designed to do this automatically or not.
Per the Oracle docs , add this information to 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.