Inheritance security rules violated by type: 'MySql.Data.Entity.MySqlEFConfiguration'

Viewed 12533

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.

7 Answers

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

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

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

Upgrading nuget package to 6.10.8 fixed this for me

Related