Could not load file or assembly 'MySql.Data, Version=6.2.2.0
I am working on Desktop application with c# and Data base My开发者_如何转开发SQL. 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.
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.
and MySql.Data.dll
file in present in Project's folder in Program files folder
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.
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:
I had the same issue with one of my web application. And I found the said issue arises when you do:
- Copy & Paste the
MySql.Data.dll
somewhere in a folder. - You have a copy of any version of
MySql.Data.dll
in 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:
- 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.
Edit:
Somebody asked "Where is GAC?":
http://msdn.microsoft.com/en-us/library/yf1d93sz(v=vs.110).aspx
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.
Is MySQL.data.dll present in the same directory as the .exe file ?
If so does that MySQL.data.dll have the proper version/public key that the .exe file is looking for ?
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 :-) )
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.
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.
Check you .config file:
And compare that verisonNr to the versionNr of the file when you would add a new reference to it.
Solution:
1) remove the line from your config file and re-add the reference
2) or uninstall the MySql .net connector and install the version which your project is referencing to.
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.
I was having the same problem in a web application (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.
<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>
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).
精彩评论