Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DLL Hell - My application throws an error if Version 6.9.3.0 OR 6.8.3.0 of MySql.Data.dll is missing

Tags:

c#

mysql

Problem Context

I have written an application in C# which uses a MySqlConnector. I've added MySql.Data.dll (Version 6.9.3.0) to the References - this all works as expected on my PC (running Windows 7). However, starting with recent builds, when I try to run the application on another PC (running Windows XP), it throws an Exception on startup.

I added an UnhandledExceptionEventHandler which shows the error Could not load file or assembly 'MySql.Data, Version 6.8.3.0. (...etc...)' or one of its dependencies. The located assembly's manifest description does not match the assembly reference. File name: 'MySql.Data, Version=6.8.3.0, (...etc...).

Obviously it is looking for Version 6.8.3.0 but only finding Version 6.9.3.0 in the References - but what I want to know is why it is looking for this version when it worked correctly with earlier builds, and how I can specify which version of MySql to look for.

I know I could just add another reference to the earlier version of the .dll, but I want to understand why this is happening.

Steps taken to attempt to diagnose the problem

  • Checked the project's References after seeing this question on Stack Overflow and confirming that a reference to MySql.Data.dll has been added to the project, along with its version (6.9.3.0).

  • Searched for results relating to the Exception error message and found this article on Stack Overflow describing its cause (which I was aware of, but it confirms it)

  • A colleague asked me to confirm that the SpecificVersion property of the MySql.Data Reference is set to False (it is).

  • Tried adding an assembly binding to the config as suggested in an answer below - it does not help, the same error is thrown.

  • Replaced the MySqlData.dll on the other PC with version 6.8.3.0 as a 'dirty fix' to see what happened. It now throws the same error as before, but for missing 6.9.3.0.

  • Asked a colleague to run the application on his (Windows 7) PC - no error was generated and it worked as expected.

  • I tried using the Dependency Walker utility on the .exe as a commenter suggested but it only showed the following .dlls missing - IESHIMS.DLL (on both PCs), WER.DLL (on the XP PC), and GPSVC.DLL (on my PC). There was nothing about MySql.Data.dll. (Though I have since learned this is not a useful tool in this case - see this question.)

  • On a whim, I decided to change the SpecificVersion property of MySql.Data Reference to True - this fixes the problem.


Additional Information

My app.config file -

<?xml version="1.0"?>
<configuration>
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/> 
    </startup>
</configuration>
like image 673
Eilidh Avatar asked Dec 05 '14 09:12

Eilidh


1 Answers

Changing the SpecificVersionproperty of the MySql.Data Reference to True fixed the problem.

My hypothesis is that the application was somehow simultaneously looking for versions 6.8.3.0. and 6.9.3.0. simultaneously - however by specifying a specific version it doesn't "confuse itself" and just goes for 6.9.3.0., which is there.

like image 179
Eilidh Avatar answered Sep 28 '22 08:09

Eilidh