Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 789
Azhar Avatar asked Jan 11 '10 10:01

Azhar


3 Answers

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

like image 169
KMX Avatar answered Oct 10 '22 20:10

KMX


  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)? I've seen this give similar error messages before.

like image 33
Rob Avatar answered Oct 10 '22 21:10

Rob


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 ?

like image 41
nos Avatar answered Oct 10 '22 20:10

nos