错误提示:
The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception.
异常详细信息:
PM> add-migration InitialModel
System.TypeInitializationException: The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception. ---> System.InvalidOperationException: The DbConfiguration type 'MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6' specified in the application config file could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260883 for more information. ---> 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.
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationLoader.TryLoadFromConfig(AppConfig config)
--- End of inner exception stack trace ---
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationLoader.TryLoadFromConfig(AppConfig config)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForAssembly(Assembly assemblyHint, Type contextTypeHint)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForContext(Type contextType)
at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..cctor()
--- End of inner exception stack trace ---
at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..ctor()
at EF.Demo.MySql.Migrations.Configuration..ctor() in D:\SourceCode\ZhaoCode\ToolsAndFrameworks\EntityFramework\EF.Demo.MySql\Migrations\Configuration.cs:line 10
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration(Type contextType, String configurationTypeName, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
上下文代码:
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class Context : DbContext
{
public Context() : base("name=MyContext")
{
}
public DbSet Users { get; set; }
}
配置文件:
寻求一个解决办法,多谢。