17

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.

Nasreddine
  • 36,610
  • 17
  • 75
  • 94
Azhar
  • 20,500
  • 38
  • 146
  • 211

8 Answers8

23

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

Community
  • 1
  • 1
KMX
  • 2,631
  • 1
  • 23
  • 28
  • 5
    Setting 'Copy To Local' solved my issues with godaddy hosting. Thanks and +1 :) – Jose Cherian Jul 10 '12 at 01:44
  • 1
    where can i find GAC ? – Ankit Agrawal Feb 27 '14 at 10:09
  • @AnkitAgrawal GAC is here http://msdn.microsoft.com/en-us/library/yf1d93sz(v=vs.110).aspx – KMX Apr 02 '14 at 11:58
  • 1
    I had this issue because the strong assembly name I was passing to `dbmetal` didn't match the version that was in my GAC. Use `gacutil /l MySql.Data` to check what version is in your GAC, if any. – DJH Jan 28 '15 at 10:38
  • @KMX i have 3 dot net versions of `Mysql dll` which one to copy ? – Moeez Nov 09 '20 at 07:23
  • @Moeez copy the latest one, or the one that is found in GAC! make sure you always use the latest unless your application explicitly depends on other versions. – KMX Oct 11 '21 at 07:01
10
  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.

Rob
  • 45,296
  • 24
  • 122
  • 150
3

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 ?

nos
  • 223,662
  • 58
  • 417
  • 506
2

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.

Arve
  • 7,284
  • 5
  • 37
  • 41
  • Just looked at a MySql.Data. It does not look like it is mixed mode or bound to 32 bit. My second guess is probably not relevant in this case – Arve Jan 11 '10 at 10:19
1

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.

Brabbeldas
  • 1,939
  • 4
  • 20
  • 32
1

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.

Charles Iams
  • 66
  • 1
  • 1
  • 8
  • also, if a software product is configured for an older version of the connector (e.g. 6.9.9) you cant just install the current mysql connector (e.g. 8.0) but have to refer to the documentation of the vendor, and which version is supported – MacMartin May 17 '19 at 09:20
1

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>
Alexandre Neukirchen
  • 2,713
  • 7
  • 26
  • 36
0

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

Tommy Carlier
  • 7,951
  • 3
  • 26
  • 43