MySQL connector 6.7.4 and Entity Framework 5 exceptions

The trick to solving this was:

  1. Add references to the MySql.Data and MySql.Data.Entity libraries of the correct version (6.7.4.0 for .NET 4.5, in my case) to the project.
  2. Edit machine.config with your editor run as administrator, and replace all occurences of MySQL version 6.6.5.0 by 6.7.4.0.

For the second step, note that there are multiple machine.config files, one for each framework version (3.0, 3.5, 4.0) and architecture (32-bit, 64-bit). Also note that the machine.config file for .NET 4.5 is in the .NET 4.0 folder. You can find the machine.config files in:

C:\Windows\Microsoft.NET\Framework\\Config

And:

C:\Windows\Microsoft.NET\Framework64\\Config

If there are no references to MySQL in the machine.config file, you might not have installed MySQL for Visual Studio. Either do that, or add the following to the app.config file of your project:

<system.data>
    <DbProviderFactories>
        <add name="MySQL Data Provider"
            invariant="MySql.Data.MySqlClient"
            description=".Net Framework Data Provider for MySQL"
            type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
</system.data>

Note however, that when you both install MySQL for Visual Studio and add the above snippet to your app.config file, then you'll get this exception:

ConfigurationErrorsException: Column 'InvariantName' is constrained to be unique. Value 'MySql.Data.MySqlClient' is already present.


I don't like to edit machine.config. Just add this redirect to web.config:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-6.6.5.0" newVersion="6.7.4.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

Using this should stop the exception that Virtlink mentioned:

<system.data>
    <DbProviderFactories>
        <remove name="MySQL Data Provider" />
        <add name="MySQL Data Provider"
            invariant="MySql.Data.MySqlClient"
            description=".Net Framework Data Provider for MySQL"
            type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
</system.data>

Especially note the <remove name="MySQL Data Provider" /> line.