C# – Could not load file or assembly ‘MySql.Data, Version=6.2.2.0

cdatabaseMySQLnet

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.

Best Answer

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