edmx error 'Unable to cast object of type 'MySql.Data.MySqlClient.MySqlProviderServices' 'System.Data.Common.DBProviderServices'
Asked Answered
B

3

8

Getting edmx error Unable to cast object of type 'MySql.Data.MySqlClient.MySqlProviderServices' to type 'System.Data.Common.DBProviderServices' when trying to open edmx designer for MySQL model. I have both Entity Framework 6 for SQL service in the project as well as references to MySQL.

Here is what I have in app.config

<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, 
MySql.Data.Entity.EF6"/>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, 
EntityFramework.SqlServer" />
</providers>
<system.data>
<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=8.0.13.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
Bradleybradly answered 31/10, 2018 at 14:39 Comment(1)
Same problem, did you find any solution?Waugh
R
9

For those of you upgrading to VS2019 and installing MySQL for Visual Studio 1.2.9, you need to edit the following line in your .edmx file (right click the .edmx file inside VS, select Open With... then pick XML (Text) Editor):

        <DesignerProperty Name="UseLegacyProvider" Value="true" />

To the following:

        <DesignerProperty Name="UseLegacyProvider" Value="false" />

I started to have that exact same error message when I tried to open an .edmx file after upgrading so I created a new one from scratch then ran a diff to see what changed.

Reconcile answered 23/10, 2019 at 0:54 Comment(1)
Damn, looks like the .edmx I'm working with already has that. I was able to open it before, after seeing I had to get Connector/NET, but couldn't run the "Update model from database." I then installed the MySQL VS Plugin, which after running the Configuration Tool, it popped up the Update model dialog so I thought it was good. It asked me restart VS then and now I'm back to this crap, not even able to open the .edmx. ArghSapers
W
3

I've got the solution, the problem was the incompatibility between the .net connector's version and the dll's version.

In my case the project was using MySql.Data dll's version 6.9 but the connector's version was 8.0. So I've replaced the .net connector with the right one (same version).

Waugh answered 20/12, 2018 at 9:52 Comment(1)
Yeah this solved it for me. A co-worker told me to get the "Connector/NET v6.8+" and I just went and downloaded the latest version, thinking that'd be sufficient. Apparently it wasn't. Uninstalled that and installed v6.8.3 and that allowed me to open the .edmx. I'm not sure where in the project it references that v6.8 though.Sapers
K
0

I found the best solution for this.

  1. I change target .NET Framework to 4.5.2 (in Project Properties)

  2. Change MySQL.Data library to v6.10.8 (NuGet)

Kentledge answered 9/2, 2019 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.