none
[A]MySQL.Data.MySqlClient.MySqlConnection cannot be cast to [B]MySQL.Data.MySqlClient.MySqlConnection.

    Question

  • I am posting this question here because even though it is a MySQL question, the problem is (a) happening in Visual Studio, and therefore related to that Microsoft, and (b) in my opinion, the problem is not really particular to MySQL - and could just as easily happen with SQL Server. I hope you agree.... if not, I will remove this question from this forum...

    I have a WinForms / .Net 4.0 application in Visual Studio 2015 Update 3, Windows 10 Pro.
    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 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 search my entire solution for any references to 6.9.8 and I've found nothing. Any ideas? Thank you...

    Fabricio Rodriguez - Pretoria, South Africa


    • Edited by Fabs1977 Thursday, August 11, 2016 2:29 PM
    Thursday, August 11, 2016 2:26 PM

Answers

  • Since you're adding a tableadapter, in the designer I assume, did you update the tooling support for MySQL when you updated to 6.9.9? Based upon the paths being returned it appears that the designer is trying to use 6.9.8 (from private assemblies which indicates an extension) whereas you've updated the MySQL runtime to 6.9.9.

    This looks like a tooling problem with MySQL extension. You probably need to post this question on their forums.

    Thursday, August 11, 2016 5:32 PM
    Moderator
  • Ok, very good suggestion. I will do so. Thanks CoolDadTx

    Fabricio Rodriguez - Pretoria, South Africa

    Thursday, August 11, 2016 6:32 PM

All replies

  • You somehow have two different versions of the "MySQL.Data.dll" referenced - 6.9.8 and 6.9.9. And to be certain to not screw up, the Compiler will not convert between those two automatically.

    Could it be you have one of them referenced indirectly? If you got any DLL referenced that in turn was build against the 6.9.8 version, that one would return the 6.9.8 version of the MySQLConnection and force the 6.9.8 version into the namespace/references.

    The more current appears to be in the Global Assembly Cache, while the older one is at "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies\MySQL.Data.dll".

    Thursday, August 11, 2016 2:55 PM
  • This is not really a VS issue. The problem is that you have 2 different versions referenced. This will cause a compiler warning. Since you're using VS 2015 you should be able to go to Solution Explorer, right click and select Manage NuGet Packages for Solution and see the NuGet packages being used by your projects. Since you seem to have different versions you should see the Updates tab show MySQL and the Consolidate tab should show the projects with mismatches. Consolidate the projects to use the same version and the problem should go away.

    If you do not see any updates or consolidations then at least 1 of your projects isn't using NuGet to get MySQL. Look at the Installed tab and confirm each project that is using MySQL has a NuGet reference to it. Fix any that don't which generally means manually removing the reference from the project and then adding it via NuGet.

    In the rare cases you may need to do a binding redirect but that shouldn't be the situation here.

    Michael Taylor
    http://www.michaeltaylorp3.net

    Thursday, August 11, 2016 3:00 PM
    Moderator
  • Thank you so much for your prompt reply. I did try "Manage NuGet Packages for Solution". Unfortunately, the "Consolidate" tab is empty. The "Installed" tab also correctly shows the three projects in the solution that are using MySQL.Data.dll. And it shows all three as using the exact same version of MySQL.Data.dll. I also went to those three projects, expanded the "References" node, and viewed the properties of MySQL.Data.dll for the three projects. And indeed, all three are the same version - 6.9.9 - and from the same location: C:\Users\Fabs-LenovoY70\Source\Workspaces\Tracker\Tracker\packages\MySql.Data.6.9.9\lib\net45\MySql.Data.dll

    I did a search in the entire solution for "*6.9.8*" as well as "*PrivateAssemblies*" (as that is the folder the offensive dll is in) but that turned up nothing. I just don't see my solution referencing that file anywhere! Yet it's obvious that it is....

    I also tried uninstalling the MySQL.Data.dll package (in the NuGet "Installed" tab) and reinstalling it, but it didn't help...

    On a side note, there was a C:\Users\Fabs-LenovoY70\Source\Workspaces\Tracker\Tracker\packages\MySql.Data.6.9.8\lib\net45\MySql.Data.dll package in my Solution's folder - an older version from before I updated the MySQL.Data.dll package to 6.9.9 using the NuGet Update tab. But it's not referenced anywhere in my solution. Just in case, I deleted the folder, but it made no difference.

    It's really weird...


    Fabricio Rodriguez - Pretoria, South Africa


    • Edited by Fabs1977 Thursday, August 11, 2016 5:19 PM
    Thursday, August 11, 2016 5:16 PM
  • Since you're adding a tableadapter, in the designer I assume, did you update the tooling support for MySQL when you updated to 6.9.9? Based upon the paths being returned it appears that the designer is trying to use 6.9.8 (from private assemblies which indicates an extension) whereas you've updated the MySQL runtime to 6.9.9.

    This looks like a tooling problem with MySQL extension. You probably need to post this question on their forums.

    Thursday, August 11, 2016 5:32 PM
    Moderator
  • Ok, very good suggestion. I will do so. Thanks CoolDadTx

    Fabricio Rodriguez - Pretoria, South Africa

    Thursday, August 11, 2016 6:32 PM
  • I had the same problem on Visual Studio 2015 Enterprise and after a long time I found the solution.

    I did the following steps(maybe one or two are optional) in two computers and worked(both are Windows 10):

    1) Remove the MySqlData reference you have on your visual studio

    2) Remove, if any, the Mysql.Data reference on nuget

    3) Open Server Explorer windown on your VS and delete any server connection you have to your mysql database.

    4) Close Visual Studio

    5) Open MySql Installer, or control panel if you have no MySql Installer, and uninstall your MySql Connector 6.9.9

    6) Open C:\Windows\Microsoft.Net\assembly\GAC_MSIL\MySql.Data and delete the folders like vXX_6.9.9

    7) Install MySql Conector 6.9.8. Download it here: https://downloads.mysql.com/archives/c-net/

    8) Open Visual Studio

    9) Add Reference to your 6.9.8 MySql.Data.dll. You find it on C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.8\Assemblies\v4.0

    10) On VS, open the Server Explorer and create a new conection to your database.

    11) Create your dataset and be happy.

    Hope it helps you.

    Kind regards.

    Edit: add the detail that I did it on VS 2015 Enterprise
    • Edited by SubZero do Cachambi Friday, March 3, 2017 6:33 PM link to mysql connector 6.9.8
    • Proposed as answer by Ronal Funes Friday, June 9, 2017 3:02 AM
    Friday, March 3, 2017 6:30 PM
  • Thanks for your input, it worked for me.
    Tuesday, August 1, 2017 5:42 PM
  • I had the same problem on Visual Studio 2015 Enterprise and after a long time I found the solution.

    I did the following steps(maybe one or two are optional) in two computers and worked(both are Windows 10):

    1) Remove the MySqlData reference you have on your visual studio

    2) Remove, if any, the Mysql.Data reference on nuget

    ..........

    11) Create your dataset and be happy.

    Hope it helps you.

    Kind regards.

    Edit: add the detail that I did it on VS 2015 Enterprise

    You are my angel !!! 

    thanks a lot !!!!!!!



    • Edited by hichamito Monday, December 11, 2017 11:56 AM
    Monday, December 11, 2017 11:55 AM