Click here to Skip to main content
15,883,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I am having a problem with a class library project where a MySql dll is referenced. I am using this class library to make CRUD operations in my projects to avoid rewriting the same code over and over again. In class library projects I have utility class where I can log errors, conenct to Oracle, mySQL and MSSQL databases and do some stuff.

I have built this class library let's say X.dll(the project builds without errors) and add this X.dll reference in another project (Assume Project A) in order to do some CRUD operations. It seems like the code for Oracle, MSSQL and logging works and I can even step into referenced dll code from my Project A and debug the code from there. But when I try to some processing by using the mySQL class that I have written in class library project doesn't allow me to step into the code, totally ignores and throws an exception. The exception details are;
Could not load file or assembly 'MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)


I have checked the MySql.Data dll properties and its version is 6.7.4.0 and it is referenced correctly in the project and I also placed the MySql.Data.dll file to my bin folder. I also tried installing MySql dll by using NuGet and still I have the sam error.

I have also added the following code to config file but still no good.
XML
<system.data>
    <DbProviderFactories>
        <clear/>
        <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
    </DbProviderFactories>
</system.data>


Btw, my class library and my Project A are both in Framework 4.0.

If some have any other recommendations I will be more than happy to hear about it! Thanks in advance.
Posted
Comments
Vedat Ozan Oner 28-Feb-14 5:29am    
have you tried to edit your project definition file (csproj)? remove all references to 'MySql.Data.dll' and add the reference again. And possibly, dll file may be corrupted itself. Clean installation may solve your problem.
wonder-FOOL 28-Feb-14 6:34am    
Hi, Vedat, no I didn't do the deletion of the refeneces and readding them. But I have tried cleaning the project but it didnt help. Anyways Maciej's solution fixed it. Thank you for your time tho.
Maarten Kools 28-Feb-14 5:35am    
Do you have a MySql.Data assembly in your GAC by any chance? Looks like it's finding some assembly, but not the right version. See also here[^]
wonder-FOOL 28-Feb-14 6:35am    
Yeah I have seen that solution earlier while searching for an answer but I couldn't figure out a solution thats why I asked it here.
Maarten Kools 28-Feb-14 6:39am    
The solution is indeed what Maciej posted, and the why is probably because an older version was found in the GAC. The GAC will always take precedence over the bin folder, which is actually rather annoying sometimes.

1 solution

Download[^] and install MySQL connector (ADO.NET Driver for MySQL (Connector/NET)). If it won't help, please let me know.

Other data providers: ADO.NET Data Providers[^]
 
Share this answer
 
Comments
wonder-FOOL 28-Feb-14 6:32am    
Hello Maciej thanks for your help that indeed solved my problem but can you tell me why or how? Because with NuGet I did install MySqlData, EF.. but it didn't solve my prolem. By installing this driver what it did? Also when I build and publish my project A to the production environment, do I have to install that MySQL connector to the production environment as well? Again your help is much appreciated.
Maciej Los 28-Feb-14 7:10am    
MySQL ADO.net connector is not standard .NET library for windows. You need to install it on each client workstation, where you want to install your program.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900