C# – Inheritance security rules violated by type: ‘MySql.Data.Entity.MySqlEFConfiguration’

asp.net-mvccentity-frameworkMySQL

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.

Best Answer

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