0

I developed MVC project using VS2015 with MySQL as database.
I uploaded the project to azure for testing and I created a copy of my MySQL database in azure too.
However, when I tried to open the website I got this error:

[A]MySql.Data.MySqlClient.MySqlConnection cannot be cast to [B]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:\Windows\Microsoft.Net\assembly\GAC_MSIL\MySql.Data\v4.0_6.5.4.0__c5687fc88969c44d\MySql.Data.dll'. Type B originates from 'MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' in the context 'Default' at location 'D:\local\Temporary ASP.NET Files\root\0b5c8b85\f7b6d016\assembly\dl3\b34b00a3\00f26175_a4c8d101\MySql.Data.dll'.


this problem occured only in azure but the application works locally. I understood that, the problem is beacause of the MySQL connector/net version installed in azure.
Can anyone help me solve this?
I found a code to be added in .config file but it bypass the error only which is not useful for me.

Solution
add this to 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.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
 </DbProviderFactories>
</system.data>
Mohammed AlAamri
  • 71
  • 2
  • 2
  • 8

2 Answers2

0

You're using different versions of the MySql.Data DLL - Version=6.5.4.0 and Version=6.9.9.0 ( it's in the exception)

Change your config file to use 6.5.4.0 (it currently specifies 6.9.9.0).

Mark Willis
  • 818
  • 12
  • 19
-1

try updating the package in both locations. looks like a simple version difference to me

lenny
  • 734
  • 2
  • 15
  • 43