尝试添加新的数据库连接时出现错误 "Could not load file or assembly MySql.data"

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

我正在尝试添加一个新的 MySql 数据库连接。我的 MySql.Data 版本是 6.9.9.0,在我的 EFModel 项目的 app.config 和项目的 Nuget 包管理器中引用为这个版本。

当我测试它时,与我的服务器建立了良好的连接,但是当我点击 "OK" 时它显示错误:

"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."

问题是这个版本没有写在我的任何配置文件的解决方案中。

这是我的 app.config 文件:

<?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>

我为此苦苦挣扎了 3 天,但在 SO 或 Internet 中找不到任何解决方案或相关问题,因为我发现的每个问题都与向数据库添加新连接或显示的版本无关app.config 中未列出的错误是我的情况。我真的不明白是什么原因造成的。

请帮忙! :/

无需过多搜索。它告诉您它试图加载的程序集与您的 application.config 文件中引用的程序集的版本不匹配。

要在此处引用另一个问题:

The .NET Assembly loader is unable to find 1.2.0.203, but did find a 1.2.0.200. This assembly does not match what was requested and therefore you get this error. In simple words, it can't find the assembly that was referenced. Make sure it can find the right assembly by putting it in the GAC or in the application path.

The located assembly's manifest definition does not match the assembly reference

这也在另一个答案中链接:The located assembly’s manifest definition with name xxx.dll does not match the assembly reference

希望对您有所帮助。

[重复]

我只需要卸载 MySql 连接器 6.9.10,然后安装 6.9.8.0 版本,如答案顶部的副本 link 中所述,但我没有不得不添加一个新的连接,我的两个连接项目的基础显示得很好!

根据我的说法,link 以前版本的 MySql 连接器很难找到!

但现在我很放心,希望这可以帮助其他人:D

当 .csproj 文件中的 MySql.data 版本与 App.config 文件中的版本不匹配时(由于手动更改等),可能会发生这种情况。尝试卸载软件包并重新添加。