【发布时间】:2018-01-27 17:54:24
【问题描述】:
错误:
An unhandled exception of type 'System.IO.FileLoadException' occurred in WindowsFormsApplication4.exe
Additional information: Could not load file or assembly 'MySql.Data, Version=8.0.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
信息:
- Visual Studio 2015
- Windows 10 - x64
- C#
- MySQL 6.9.9
问题:
我使用 MySQL 制作了一个类库来对我的在线数据库运行各种查询。
在我的单独项目中包含 dll 后,我使用的唯一代码行如下:(它会引发异常)
// Runs a simple select statement to find matches for 'John Doe' in my online MySQL database table... and stores results to a dataset
DataSet ds = MyDllNameSpace.Database.People.Load("John", "Doe");
App.Config 文件:
我的 dll 项目:(我没有签署这个项目)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<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.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data></configuration>
我的单独项目:(我没有签署这个项目)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.8.0" newVersion="8.0.8.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
我搜索过/尝试过的内容:
- 确保在两个项目中使用相同版本的 MySQL
- 将 dll 放入我的库和 MySQL 中的我的单独项目的 bin 文件夹中,并将它们添加为参考
- 还尝试将我的库和 MySQL 的 dll 添加到单独的项目中并选择“始终复制”
- 更改 App.config 文件(假设问题出在此处?)
- 最后,我尝试对 dll 项目和使用相同密码的 dll 的项目进行签名(检查对程序集进行签名)。这也无济于事。 :(
谢谢
【问题讨论】:
-
经过数小时试图找出问题...原来是由于在包管理器中使用了最新的预发行版 MySql.Data。切换到最新的 STABLE 版本后,一切正常。