views:

1653

answers:

5

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.

A: 

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
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
A: 

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
A: 

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
+1  A: 
  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
+1 For mentioning the cache. No idea why I missed your answer before :(
Diago
@Azhar - which was it then, 1 or 2? :)
Rob
A: 

Since you mention the error happens in the Start Menu shortcut only and it runs fine from the Folder the problem could potentially be with the Start In folder location of the Shortcut. Make sure whatever creates the shortcut makes the Start In folder the same as the folder the application is in.

Alternatively the problem could be with the version of the MySql.Data dll you are distrubuting as already mentioned.

Diago