简体   繁体   English

无法加载文件或程序集 'MySql.Data,版本 = 6.2.2.0

[英]Could not load file or assembly 'MySql.Data, Version=6.2.2.0

I am working on Desktop application with c# and Data base MySQL.我正在使用 c# 和数据库 MySQL 开发桌面应用程序。 When I install its installer on my machine it works fine but when I install it on other machine its give following exception when try to access DB.当我在我的机器上安装它的安装程序时它工作正常但是当我将它安装在其他机器上时它在尝试访问数据库时给出以下异常。 I am using MySQL.Data.dll to communicate with MySQL.我正在使用MySQL.Data.dll与 MySQL 进行通信。

Could not load file or assembly 'MySql.Data, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies.无法加载文件或程序集“MySql.Data, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d”或其依赖项之一。 The system cannot find the file specified.系统找不到指定的文件。

and MySql.Data.dll file in present in Project's folder in Program files folderMySql.Data.dll文件存在于 Program files 文件夹中的 Project 文件夹中

Actually when I run it from its folder in Program file it run fine with no error but When i try to run it from its shortcut in Start Menu it gives that error.实际上,当我从 Program 文件中的文件夹运行它时,它运行良好,没有错误,但是当我尝试从“开始”菜单中的快捷方式运行它时,它会出现该错误。

It sounds i am 2 years late answering this post but it might be helpful for those who are still facing this issue, so here is my finding dated 1st April 2012 5pm EST:听起来我回答这个帖子晚了 2 年,但它可能对那些仍然面临这个问题的人有帮助,所以这是我在 2012 年 4 月 1 日美国东部时间下午 5 点的发现:

I had the same issue with one of my web application.我的一个 Web 应用程序遇到了同样的问题。 And I found the said issue arises when you do:我发现当你这样做时会出现上述问题:

  • Copy & Paste the MySql.Data.dll somewhere in a folder.MySql.Data.dll复制并粘贴到文件夹中的某处。
  • You have a copy of any version of MySql.Data.dll in GAC您在 GAC 中拥有任何版本的MySql.Data.dll的副本

Though application works fine on your development machine as it can see the files but when you deploy it on some other machine it actually brings the run time error.尽管应用程序在您的开发机器上运行良好,因为它可以看到文件,但是当您将其部署在其他机器上时,它实际上会带来运行时错误。

In my case, the VS2008 always pointed me with the same error as you mentioned.就我而言,VS2008 总是向我指出与您提到的相同的错误。 I then did this:然后我这样做了:

  • Removed the local copy reference of the dll删除了dll的本地副本引用
  • Referenced the DLL found in GAC引用了在 GAC 中找到的 DLL
  • And set the property "Copy Local" to "True" of the DLL by right-clicking->properties.并通过右键单击->属性将 DLL 的“Copy Local”属性设置为“True”。

Edit:编辑:

Somebody asked "Where is GAC?":有人问“GAC 在哪里?”:
http://msdn.microsoft.com/en-us/library/yf1d93sz(v=vs.110).aspx http://msdn.microsoft.com/en-us/library/yf1d93sz(v=vs.110).aspx

  1. Does the shortcut in the Start Menu set the working directory correctly?开始菜单中的快捷方式是否正确设置了工作目录? (I suspect that this is the most likely answer) (我怀疑这是最有可能的答案)

  2. Is there a different/incorrect version of MySql.Data.dll installed in the GAC (Global Assembly Cache)? GAC(全局程序集缓存)中是否安装了不同/不正确的 MySql.Data.dll 版本? I've seen this give similar error messages before.我以前见过这给出了类似的错误消息。

Is MySQL.data.dll present in the same directory as the .exe file ? MySQL.data.dll 是否与 .exe 文件位于同一目录中?

If so does that MySQL.data.dll have the proper version/public key that the .exe file is looking for ?如果是这样,那么 MySQL.data.dll 是否具有 .exe 文件正在寻找的正确版本/公钥?

When this thing happens to me it is usually one out of two things:当这件事发生在我身上时,通常是以下两种情况之一:

Make sure that MySql.Data is present on the machine where you get the error.确保出现错误的机器上存在 MySql.Data。 (It unbelievable how often a files turns out to be missing :-) ) (令人难以置信的是,文件丢失的频率有多高:-))

If MySql.Data is a mixed mode (native and managed code) 32 bit DLL.如果 MySql.Data 是混合模式(本机和托管代码)32 位 DLL。 And you executable specifies "Any CPU".并且您的可执行文件指定“任何 CPU”。 On a 64 bit machine with 64 bit .NET this will fail with error message you got.在具有 64 位 .NET 的 64 位机器上,这将失败并显示错误消息。 A solution is to specify "x86" as target for the executable.一种解决方案是指定“x86”作为可执行文件的目标。

Tommy's reason is very valid:汤米的理由很充分:

My project was referencing to an older version of the MySql.Data.dll compared to what was actually installed on my development machine.与我的开发机器上实际安装的相比,我的项目引用了旧版本的 MySql.Data.dll。 This will result in the same error.这将导致相同的错误。

Check you .config file:检查您的 .config 文件:

And compare that verisonNr to the versionNr of the file when you would add a new reference to it.并在添加新引用时将该 verisonNr 与文件的 versionNr 进行比较。

Solution:解决方法:

1) remove the line from your config file and re-add the reference 1)从您的配置文件中删除该行并重新添加引用

2) or uninstall the MySql .net connector and install the version which your project is referencing to. 2) 或卸载 MySql .net 连接器并安装您的项目所引用的版本。

I had this issue too, for me it was recreating the connection strings in project settings.我也有这个问题,对我来说它是在项目设置中重新创建连接字符串。 They were configured for a previous version of the MySQL connector.它们是为以前版本的 MySQL 连接器配置的。

I was having the same problem in a web application (C#).我在 Web 应用程序 (C#) 中遇到了同样的问题。 I managed to solve it by changing the web.config file, it was referencing version 6.2.2.0, and my dll was version 8.0.25.0.我设法通过更改web.config文件来解决它,它引用了 6.2.2.0 版,而我的 dll 是 8.0.25.0 版。

<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.25.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  </DbProviderFactories>
</system.data>

确保您放在项目文件夹中的 MySql.Data DLL 是正确的版本(在本例中为 6.2.2.0)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载文件或程序集“ mysql.data”,版本= 6.7.4.0 - Could not load file or assembly 'mysql.data,' version=6.7.4.0 无法加载文件或程序集&#39;MySql.Data,版本= 6.7.4.0 - Could not load file or assembly 'MySql.Data, Version=6.7.4.0 使用mysql企业dll消息连接mysql无法加载文件或程序集&#39;mysql.data version = 6.4.4.0 - Conect mysql with mysql enterprise dll message could not load file or assembly 'mysql.data version=6.4.4.0 BLToolkit-mysql-connector异常:无法加载文件或程序集MySql.Data,版本= 6.9.7.0 - BLToolkit-mysql-connector exception: Could not load file or assembly MySql.Data, Version=6.9.7.0 .NET 核心中 MySQL.Data 的“无法加载文件或程序集”问题 - "Could not load file or assembly" problem with MySQL.Data in .NET core 无法加载文件或程序集“ MySql.Data”,参数不正确 - Could not load file or assembly 'MySql.Data' the parameter is incorrect 无法加载文件或程序集 &#39;MySql.Data, Version=8.0.29.0.. 找到的程序集的清单定义与程序集引用不匹配 - Could not load file or assembly 'MySql.Data, Version=8.0.29.0.. The located assembly's manifest definition does not match the assembly reference 无法加载文件或程序集 MySql.Data,在异常中引用两个文件 - Could not load file or assembly MySql.Data, referencing two files in exception 收到错误“文件或程序集名称&#39;MySql.Data,版本= 6.7.4.0…&#39;” - Getting an Error "File or assembly name 'MySql.Data, Version=6.7.4.0 …' 无法加载文件或程序集&#39;MySql.Data,版本= 6.9.5.0,区域性=中性,PublicKeyToken = c5687fc88969c44d&#39;或其依赖项之一。 - Could not load file or assembly 'MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM