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

前端 未结 3 1782
你的背包
你的背包 2021-01-05 09:35

I am getting this strange inexplicable error when I uploaded my application to a server for testing. From what I studied, it seems to be caused by conflicting MySql.Data, th

相关标签:
3条回答
  • 2021-01-05 09:51

    As the expection says, you are using two different versions of MySql. Version 6.2.3.0 and version 6.3.7.0. From this point on I can only guess: Maybe you are using a dll built with a different version of MySql (and it allows installation side by side).

    0 讨论(0)
  • 2021-01-05 10:08

    I got the same problem but years later!

    My server has installed in gac the MySql Connector 6.4.6 version, but I'm working with the 6.8.3 version, I was getting the "cannot be cast error". I fixed it by adding the following section to the .config file

    <system.data>
        <DbProviderFactories>
          <!-- Removes the dll installed in gac-->
          <remove invariant="MySql.Data.MySqlClient" />
    
          <!-- Add the dll copied in the bin folder-->
          <add name="MySQL" description="ADO.Net driver for MySQL" invariant="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data"/>
        </DbProviderFactories>
    </system.data>
    
    0 讨论(0)
  • 2021-01-05 10:08

    I had the same issue, conflict between version 18 and 19. Doing this in web.config fixed it. Set the new version to the one you have in your machine.

    <dependentAssembly>
            <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-8.0.18.0" newVersion="8.0.19.0" />
          </dependentAssembly>
    
    0 讨论(0)
提交回复
热议问题