Bug #91030 Entity Framework Code-First Migration to database does not work
Submitted: 25 May 2018 17:05 Modified: 10 Aug 2022 18:44
Reporter: Bari Tobi Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:8.0.11 OS:Windows
Assigned to: CPU Architecture:x86
Tags: entity framework

[25 May 2018 17:05] Bari Tobi
Description:
Using Entity Framework with latest versions of libraries (See "how to repeat" section), it no longer works to do a code-first migration. I.e. set up the domain model in code and then let the Entity Framework via the MySql Entity Framework connector create the equivalent database tables. This used to work in a previous version.

The error message I get is that there is something wrong with the database connection string although it is a very simple one and working in the previous version. I doubt that this is the problem. I would suggest that the error message handling was improved too to give some more information on what is really wrong. There seem to be many people on various forums that are puzzled by this error message and there seem to be many reasons for it to appear not all related to the connection string.

The error occurs when issuing the "enable-migrations" command in the Packet manage Console according to the article. The error message you get is:

"An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure."

Inner Exception stack is:
System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.MethodAccessException: Attempt by method 'MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(System.Data.Common.DbConnection)' to access method 'MySql.Data.MySqlClient.MySqlConnection.get_Settings()' failed.
   at MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection connection)
   at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)

How to repeat:
My VS library versions:
- Entity Framework 6.2.0 (though it states in 6.0.0, I know 6.2 is installed via NuGet)
- MySql.Data v8.0.11
- MySql.data.Entity 6.10.7

There is a blog description of how to work around this in an older version of .net (4.5) using older versions of the needed libraries: https://vnextcoder.wordpress.com/2015/10/04/mysql-net-entity-framework-code-first-migratio...

Downloading the test code in that article (link to GitHub repository link at the end of article), it is possible to make it work with those libraries he used following the blog post. (however, there is an app.config updated needed that he does not explicitly state: Change MySql.Data.Entity.EF6 v6.9.7.0 to v6.8.3.0 according to the version that actually works).

Since the code has not changed, not the connection string, I assume this is a bug or a breaking change in some library upgrade.

Suggested fix:
Use the code in that blog. Update binaries to the latest version and make it work.
[25 May 2018 17:14] Bari Tobi
Updated bug report. Version number was wrong by mistake.
[31 May 2018 11:54] Chiranjeevi Battula
Hello Tob Fja,

Thank you for the bug report.
Verified based on internal discussion with dev's.

Thanks,
Chiranjeevi.
[25 Jun 2018 11:18] Paul Reeder
I had the same problem.  In order to work around it, I had to downgrade to:

MySql.Data - 6.9.12 (6.10.7 and 8.0.11 exhibited the problem)
MySQL.Data.Entity - 6.8.8 (6.9.12 and 6.10.7 exhibited the problem)

I did not have to downgrade EntityFramework from 6.2.0
[6 Nov 2018 12:19] Gianpiero Caretti
I had the same problem.  But I solved the issue by upgrading to:

MySql.Data - 8.0.13
MySQL.Data.Entity - 6.10.8

I did not have to downgrade EntityFramework from 6.2.0
[31 Jan 2019 22:17] Bernhard Doebler
I get this message "{"The provider did not return a ProviderManifestToken string."}" While I'm on latest versions :(

  <package id="MySql.Data" version="8.0.14" targetFramework="net46" />
  <package id="MySql.Data.Entity" version="6.10.8" targetFramework="net46" />
[6 Apr 2019 11:11] robert ivanc
It's been 10 months on this critical bug, and no fix?? Seriously? 
How this even get through your testing?
[1 Jun 2019 5:03] C B
code-first migration does not work and neither does database-first.

Its now over a year since this CRITICAL bug report was out there.  

Someone needs to grab this bull by the horns and get a set of connectors and dll's out there that work and package it and give technical examples of how to set them up that work.

Using most of the connector and dll packages seems to be the technical equivalent of racing down the rabbit hole to spend time with Alice. In this day and age when you press the uninstall button you should not have to go rooting through the registry for the left over bits. The nuget packages don't work properly either.   

I know this is GNU and I don't mean to be harsh but this is a nightmare out here. The DB seems pretty rock solid but the dll's seem to be nothing short of a disaster. Nothing seems to work properly. 

Please put something out that works and pull all the other stuff because its making a mess of things.
[3 Jun 2019 4:17] C B
Again this is beyond the pale.  

"The provider did not return a ProviderManifestToken string."

I have tried so many DLL and Connector packages it makes your head spin.  One gives this error, the next does not but it does not run the data entity wizard.  How can that happen?  Don't you have at least the same basic interface on the DLL's and the database connection?

Anyway rant off I guess.

For everyone else here waiting for a fix this is something I got to work with Server 8.0 on Windows 10 that does a connection and allows log in with ASP.NET Identity 2.0 and will at least run the Data Entity Wizard to completion.

......

Install Connector / Net 6.10.7 

DLL's

c:\..\EntityFramework.6.2.0\lib\net45\EntityFramework.dll
C:\..\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll 

C:\..\MySql.Data.6.10.7\v4.5.2\MySql.Data.dll
C:\..\MySql.Data.6.10.7\v4.5.2\MySql.Data.Entity.EF6.dll

Web.Config

<configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    </configSections>

<connectionStrings>
 <add name="DefaultConnection" connectionString="server=localhost;user id=<yourid>;password=<yourpassword>;persistsecurityinfo=True;database=<yourdbname>" providerName="MySql.Data.MySqlClient" />
   </connectionStrings>

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  <providers>
  
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
 <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.10.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
        </providers>
</entityFramework>
   
<system.data>
   <DbProviderFactories>
       <remove invariant="MySql.Data.MySqlClient"></remove>
      <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.10.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
</system.data>

I hope this helps some people out there but I have a funny feeling your mileage may vary.
[27 Jun 2019 21:07] Roberto Ezequiel Garcia Ballesteros
Posted by developer:
 
Hi,

I download the github project and updated MySql references to use 6.10.8 version for MySql.Data and MySql.Data.Entity and I was able to run migrations successfully. 

The error could be due to some incorrect version in app.config or .project files.

Also note the package MySql.Data.Entities is not supported by us.

Regards.
[10 Sep 2019 13:50] Kris Nobels
Hello,

I go with this guide https://dev.mysql.com/doc/connector-net/en/connector-net-installation.html

But with version 8.0.17 i have problems.

Anyone got this working ?
[10 Sep 2019 13:55] Kris Nobels
Some handy link how it needs to be done. 
https://dev.mysql.com/doc/connectors/en/connector-net-entityframework60.html
[10 Aug 2022 18:44] Daniel Valdez
Bug not reproducible.