问题
I have a WinForms / .Net 4.0 application in Visual Studio 2015 Update 3. When I try to add, or edit, a TableAdapter in any of my DataSets, I get this error:
The wizard detected the following problems when configuring the TableAdapter:
Details:
Generated SELECT statement. [A]MySQL.Data.MySqlClient.MySqlConnection cannot be cast to [B]MySQL.Data.MySqlClient.MySqlConnection. Type A originates from 'MySQL.Data Version 6.9.8.0, Culture=neutral,PublicToken=c5687fc88969c44d' in context 'Default' at location 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies\MySQL.Data.dll'. Type B originates from 'MySQL.Data, Version 6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' in context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\MySQL.Data\v4.0_6.9.9.0_c5687fc88969c44d\MySQL.Data.dll'.
Obviously it is complaining about two different versions of the MySQL.Data.dll 6.9.8 and 6.9.9. What I don't understand though is why or where is it referencing version 6.9.8.0? If I look at my project's references, it is using MySQL.Data.dll version 6.9.9.0. This is a NuGet package at location:
C:\Users\Fabs-LenovoY70\Source\Workspaces\Tracker\Tracker\packages\MySql.Data.6.9.9\lib\net45\MySql.Data.dll
I've tried the solution at [A]MySql.Data.MySqlClient.MySqlConnection cannot be cast to [B]MySql.Data.MySqlClient.MySqlConnection but didn't work.
I've searched my entire solution for any references to 6.9.8 and I've found nothing. I've been Googling for a solution for a whole day now and have found nothing that's worked. :( Any ideas anyone? Thank you...
回答1:
I am having the same issues with VS 2012. I am not sure how to fix it but after spending quite a bit of time on it here is what I see is happening.
Over all your/my system is at mysql.data.dll version 6.9.9.0. I am not able to downgrade this to 6.9.8.0 When I do I create other version problems with mysql.data.dll that seem to be unresolveable with my knowledge level.
I chased down all 6.9.8.0 versions of the DLL and removed them, ensuring that there was a 6.9.9 version in its place. Once I have done this I am not able to add a data connection to a MySQL Database. When I try I get the error An error occurred that is normally caused by not having Visual Studio properly installed. In addition non of the previously defined data connections work.
Not having MYSQL-connector-net-6.9.9 installed gives an error of "Cannot obtain provider factory for data provider named MySql.Data.MySqlClient" and you don't even get to the error described above by the OP.
- I have tried various connector-net versions and this does not fix the problem.
I have no references to 6.9.8.0 in any of my projects but clearly for some reason VS needs it to create the data connections.
Update:
I removed MySQL, then went through and deleted all mysql*.dll and all config files. I then used the MySQL Installer 5.7.14 found at http://dev.mysql.com/downloads/installer/
The installer still installed the mysql.data.dll version 6.9.8.0 and it still causes the error.
Update: The problem is with MySQL Connector / Net. It is using version 6.9.9.0 of the DLL and everything else is using 6.9.8.0 Go to your community installer and uninstall connector / net. Then go to https://downloads.mysql.com/archives/c-net/ and get version 6.9.8 of the connector / net. Install this and everything should be fine. It has worked on my system.
回答2:
Uninstalling 6.9.9 and installing 6.9.8 worked for me. I had uninstallation problems and I had to use this tool from microsoft to clear the connector install/uninstall problem https://support.microsoft.com/en-us/help/17588/fix-problems-that-block-programs-from-being-installed-or-removed Finally I had to make sure that mysql.data.dll referenced is version 6.9.8. I guess it's the only solution after spending countless hours up and down.
回答3:
Make sure you check your app.config (or web.config) files. I had to downgrade from 6.10.8 to 6.10.7 .Net Connector. I wiped all the 6.10.8 version dlls from my system, rebuilt the project and it was still asking for 6.10.8. When you downgrade a Nuget package in Visual Studio, the .config is not altered - it was still at 6.10.8. I changed it to 6.10.7 and everything worked.
来源:https://stackoverflow.com/questions/38891056/conflicting-versions-of-mysql-data-dll-in-net-project-not-allowing-me-to-add-ed