InvalidCastException in Windows Azure connecting to MySQL DB

I have just started using Azure and I am having a problem accessing the MySQL DB I set up. It appears as if Azure is referencing the MySQL.Data.dll version 6.5.4 instead of the version I require, MySQL.Data.dll v6.8.3. I receive the following error:

MySql.Data.MySqlClient.MySqlConnection cannot be cast to MySql.Data.MySqlClient.MySqlConnection. Type A originates from 'MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' in the context 'Default' at location 'D:WindowsMicrosoft.NetassemblyGAC_MSILMySql.Datav4.0_6.5.4.0__c5687fc88969c44dMySql.Data.dll'. Type B originates from 'MySql.Data, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' in the context 'Default' at location 'C:DWASFilesSitestestTemporary ASP.NET Filesrootfc8f3c274f9201b0assemblydl3ca8ec5e274482a5e_285fcf01MySql.Data.dll'.

I tried using my application with v6.5.4 but I require v6.8.3 for it to work. Numerous searches have not revealed a solution. Does anyone have any ideas? The checked using Web Matrix that the version in the bin directory is 6.8.3. How can I reference this correct dll?


I had the same problem. The problem is that on the server there is installed a lower version of the MySql library.

You can bypass this modifying your web.config file:

<system.data>
  <DbProviderFactories>
    <remove invariant="MySql.Data.MySqlClient" />
    <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.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  </DbProviderFactories>
</system.data>
链接地址: http://www.djcxy.com/p/72710.html

上一篇: 奇怪的例外:Active Project的DLL在两个地方被引用?

下一篇: Windows Azure中的InvalidCastException连接到MySQL数据库