1

When I run "Enable-Migrations -Force" command on my Class Library project, I see following error.

Note: Mysql.Data and Mysql.Data.Entity has been installed.

System.TypeInitializationException: The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception. ---> 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.

App.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <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=10.10.10.10;Database=dbName;Uid=user;Pwd=p;" 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.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
      </provider></providers>
  </entityFramework>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
</configuration>

DbContext.cs

[DbConfigurationType(typeof(MySqlEFConfiguration))]
    public class MyDbContext : DbContext
    {
        public MyDbContext() : base("DefaultConnection")
        {

        }

        public DbSet<User> Users { get; set; }
        public DbSet<Board> Boards { get; set; }


    }
3
  • Your question is very similar to this post stackoverflow.com/questions/20767216/… Commented Oct 26, 2017 at 1:34
  • I saw this post. I tried the solution but did not work. Commented Oct 26, 2017 at 2:07
  • @huseyinm88 You can remove your comment now, as you have indicated that the solution below did in fact work Commented Jan 1, 2018 at 13:49

1 Answer 1

7

I'm having exactly the same problem in both VS 2015 and VS 2017, have tried everything and nothing works :(

--- Edit

I get the job done after downgrade the MySQL.Data to 6.8.8.0 . Worked both VS 2015 and VS 2017.

[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class Context : DbContext
{
    public Context() : base("MyContext")
    {

    }

    public DbSet<Foo> foo;

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<Foo>();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.