C# 无法加载文件或程序集 'MySql.Data,版本 = 6.2.2.0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2041051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not load file or assembly 'MySql.Data, Version=6.2.2.0
提问by Azhar
I am working on Desktop application with c# and Data base 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.
我正在使用 c# 和数据库 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. The system cannot find the file specified.
无法加载文件或程序集“MySql.Data, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d”或其依赖项之一。该系统找不到指定的文件。
and MySql.Data.dll
file in present in Project's folder in Program files folder
和MySql.Data.dll
文件存在于程序文件文件夹中的项目文件夹中
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 文件中的文件夹运行它时,它运行良好,没有错误,但是当我尝试从“开始”菜单中的快捷方式运行它时,它会出现该错误。
采纳答案by Rob
Does the shortcut in the Start Menu set the working directory correctly? (I suspect that this is the most likely answer)
Is there a different/incorrect version of MySql.Data.dll installed in the GAC (Global Assembly Cache)? I've seen this give similar error messages before.
开始菜单中的快捷方式是否正确设置了工作目录?(我怀疑这是最有可能的答案)
GAC(全局程序集缓存)中是否安装了不同/不正确的 MySql.Data.dll 版本?我以前见过这给出了类似的错误消息。
回答by Arve
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. (It unbelievable how often a files turns out to be missing :-) )
确保出现错误的机器上存在 MySql.Data。(令人难以置信的是,文件丢失的频率有多高:-))
If MySql.Data is a mixed mode (native and managed code) 32 bit DLL. And you executable specifies "Any CPU". On a 64 bit machine with 64 bit .NET this will fail with error message you got. A solution is to specify "x86" as target for the executable.
如果 MySql.Data 是混合模式(本机和托管代码)32 位 DLL。并且您的可执行文件指定“任何 CPU”。在具有 64 位 .NET 的 64 位机器上,这将失败并显示错误消息。一种解决方案是指定“x86”作为可执行文件的目标。
回答by nos
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 文件正在寻找的正确版本/公钥?
回答by Tommy Carlier
Make sure that the MySql.Data DLL you put in the Project's folder is the correct version (6.2.2.0 in this case).
确保您放在项目文件夹中的 MySql.Data DLL 是正确的版本(在本例中为 6.2.2.0)。
回答by KMX
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. And I found the said issue arises when you do:
我的一个 Web 应用程序遇到了同样的问题。我发现当你这样做时会出现上述问题:
- Copy & Paste the
MySql.Data.dll
somewhere in a folder. - You have a copy of any version of
MySql.Data.dll
in GAC
- 复制并粘贴
MySql.Data.dll
文件夹中的某处。 - 您拥有
MySql.Data.dll
GAC中任何版本的副本
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. I then did this:
就我而言,VS2008 总是向我指出与您提到的相同的错误。然后我这样做了:
- Removed the local copy reference of the dll
- Referenced the DLL found in GAC
- And set the property "Copy Local" to "True" of the DLL by right-clicking->properties.
- 删除了dll的本地副本引用
- 引用了在 GAC 中找到的 DLL
- 并通过右键单击->属性将 DLL 的“Copy Local”属性设置为“True”。
Edit:
编辑:
Somebody asked "Where is GAC?":
http://msdn.microsoft.com/en-us/library/yf1d93sz(v=vs.110).aspx
有人问“GAC 在哪里?”:http: //msdn.microsoft.com/en-us/library/yf1d93sz(v=
vs.110).aspx
回答by Brabbeldas
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. This will result in the same error.
与我的开发机器上实际安装的相比,我的项目引用了旧版本的 MySql.Data.dll。这将导致相同的错误。
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 连接器并安装您的项目所引用的版本。
回答by Charles Iams
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 连接器配置的。