22

I've created an asp.net web application which should connect to a mysql database.

I´m using entity framework 6 with an ado.net entity data model. I´ve also followed the following tutorial: https://dev.mysql.com/doc/connectors/en/connector-net-entityframework60.html#connector-net-ef6-config

However calling: DbConfiguration.SetConfiguration(new MySqlEFConfiguration());

causes my application to crash. It probably has nothing to do with this specific method, because creating a DBContext also crashes the app.

Any ideas what's causing this error?

  • .NET Framework: 4.6.1
  • MySql.Data.Entity.EF6: 6.10.4

Web.config:

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

<connectionStrings><add name="DatabaseEntities" connectionString="metadata=res://*/Database.Model.csdl|res://*/Database.Model.ssdl|res://*/Database.Model.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;&quot;" providerName="System.Data.EntityClient" /></connectionStrings><system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add description=".Net Framework Data Provider for MySQL" invariant="MySql.Data.MySqlClient" name="MySQL Data Provider" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.10.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>

Complete error:

Inheritance security rules violated by type: 'MySql.Data.Entity.MySqlEFConfiguration'. Derived types must either match the security accessibility of the base type or be less accessible.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.TypeLoadException: Inheritance security rules violated by type: 'MySql.Data.Entity.MySqlEFConfiguration'. Derived types must either match the security accessibility of the base type or be less accessible.

Jamie
  • 3,031
  • 5
  • 36
  • 59

7 Answers7

38

I downgraded MySql.Data.Entity.EF6 to an older version and it solved my problem.

Jamie
  • 3,031
  • 5
  • 36
  • 59
  • I've been fighting this for a week, what version did you downgrade to? – NorbyTheGeek Nov 15 '17 at 17:26
  • 2
    Both MySql.Data and MySql.Data.Entity are 6.9.10. MySQL Connector also 6.9.10, MySQL for Visual Studio 1.2.7 – Jamie Nov 15 '17 at 17:39
  • For information: this issue is tracked on [MySQL Connector GitHub repository](https://github.com/mysql/mysql-connector-net/pull/12) – 0xced Nov 20 '17 at 15:12
  • It's 2018 and this helped me big time after 16 hours of misery and agony and pain. – realnsleo Jan 18 '18 at 11:40
  • 1
    Make sure to delete the installed version 6.10.5 MySql.Data and MySql.Data.Entity NuGet packages and install version 6.9.10 of both packages. – Laszlo Pinter Jan 22 '18 at 05:47
  • 2
    The downgrade is not a solution. Oracle just messed up with OpenSource. We all developers are suffering. – Md. Rashidul Hasan Mar 11 '18 at 12:52
  • MySql.Data 8.0.15.0 and MySql.Data.Entity.EF6 7.0.7.0 and MySql Connector 8.0.16. Pretty pathetic really. If the big boys can't get stuff to work what chance do we have, don't they test these things? Downgrade seems like a backward step. – djack109 Jul 24 '19 at 18:21
8

Downgrade MySql.Data.Entity from version 6.10.x to 6.9.10 can solve the problem. It solved mine

Hung Vu
  • 5,624
  • 2
  • 30
  • 27
2

I've had some horrible instability problems with 6.9.10. It also seems like it has has been removed from NuGet. Under heavy load i was getting "database not found errors" sporadically.

Try 6.9.11 instead. That seems stable for me. And its available on NuGet.

  • Are you talking about the version of MySql.Data.Entity.EF6? If you are, it seems like they're using a newer version than what you're recommending. – Taegost Feb 13 '18 at 19:06
1

I did this and it worked for me

  1. Install latest versions of entityframwork and mysql.data and mysql.data.entity from nuget package manager

  2. Create your model databasefirst autogenerate

  3. Unistall mysql.data.entity and install mysql.data.entity v 6.9.10 just learn how to install or uninstall
Michael Hancock
  • 2,673
  • 1
  • 18
  • 37
1

I got the same issue after upgrading the MySql NuGet packages from 6.9.8 to 6.10.6 in VS 2017 Community. I followed the accepted answer's instructions and downgrading back to 6.9.x fixed it. Upon futher investigation, Oracle has fixed the bug in the upcoming 6.10.7 release (https://bugs.mysql.com/bug.php?id=89134).

In short, until 6.10.7 is released, downgrade back to 6.9.x! I reverted back using the Nuget package manager and didn't have to change anything else to make it work.

Matt H
  • 11
  • 1
0

The same for me with VS2017. I used MySql.Data.Entity v6.9.10.
Prior to that I also installed mysql connector for .Net version 6.9.10.

  • After that I installed the NuGet package for MySql.Data.Entity.
  • Last step was to modify the web.config accordingly:
    • connection string,
    • entity framework and
    • system.data (be aware that you have to update in the last two the version as well if you take them from mysql website)
  • Ahh not to forget I added also

    DbConfiguration.SetConfiguration(new MySqlEFConfiguration()) 
    

    in my app start up.

and it finally worked :D

zx485
  • 28,498
  • 28
  • 50
  • 59
C.Sv
  • 21
  • 3
0

Upgrading nuget package to 6.10.8 fixed this for me

flobadob
  • 2,804
  • 2
  • 22
  • 23