Eroor "Could not load file or assembly MySql.data" when trying to add a new database connection

Pierrick Martellière picture Pierrick Martellière · Nov 9, 2017 · Viewed 13k times · Source

I'm trying to add a new MySql database connection. My version of MySql.Data is 6.9.9.0 and is referenced as this in my EFModel project's app.config and in the Nuget Package Manager of the project.

When I test it, the connection with my server is well established, but when I click on "OK" it displays an error:

"Could not load file or assembly 'MySql.data, Version=6.9.8.0, Culture=Neutral, PublicKeyToken=BigNumber' or one of his dependencies. The found definition of the assembly's manifest doesn't correspond to the reference of the assembly."

The issue is that this version is not wrote in my solution in any config files.

Here is my app.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="UphairDbEntities" connectionString="metadata=res://*/DbModel.csdl|res://*/DbModel.ssdl|res://*/DbModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=***;user id=***;password=***;database=***&quot;" providerName="Mysql.Data.MysqlClient" />
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" 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.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
  <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.8.3.0" newVersion="6.8.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

I'm struggling on this for 3 days but couldn't find any solution or related issue in SO or internet since every issues I found weren't about adding a new connection to a database nor about the version displayed on the error not listed in app.config which is my case. I really don't understand what can causes this.

Please help ! :/

Answer

Pierrick Martelli&#232;re picture Pierrick Martellière · Nov 9, 2017

[DUPLICATE] Conflicting versions of MySql.Data.dll in .Net project not allowing me to add/edit TableAdapters in my DataSets

I just had to uninstall the MySql Connector 6.9.10 then install the 6.9.8.0 version as explained in the duplicate link at the top of my answer and I didn't had to add a new connection, my bases for the two connected projects were displayed well !

This link for previous versions of MySql Connector is a pain in the ass to found, according to me !

But now I'm so relieved, hope this could help some others :D