【发布时间】:2013-06-01 15:47:35
【问题描述】:
我无法启用 EF 迁移!
使用包管理器控制台,它会抛出以下内容:
PM> Enable-Migrations
System.BadImageFormatException: Could not load file or assembly 'MyApp' or one of its dependencies. Index not found. (Exception from HRESULT: 0x80131124)
File name: 'MyApp' ---> System.BadImageFormatException: Index not found. (Exception from HRESULT: 0x80131124)
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.LoadAssembly()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindType[TBase](String typeName, Func2 过滤器,Func2 noType, Func3 多个类型,Func3 noTypeWithName, Func3 多个类型与名称)
在 System.Data.Entity.Migrations.Design.ToolingFacade.GetContextTypeRunner.RunCore()
在 System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Could not load file or assembly 'MyApp' or one of its dependencies. Index not found. (Exception from HRESULT: 0x80131124)
还有:
1. 我的默认项目(在 PM CONSOLE 中)是“MyApp”
2.解决方案只有“MyApp”
3. 继承自 DbContext 的类在 'MyApp.Models'
4. 我也尝试创建一个新的解决方案,然后将所有类复制粘贴到它,它抛出了同样的错误
发生了什么?
过去我曾经在这个项目中启用了迁移,但两天后我删除了其中的所有迁移内容,因为它不是必需的。但现在我真的很需要它们
【问题讨论】:
-
如果您删除了所有迁移类,您是否删除了 __MigrationHistory 表中的记录。尝试使用一个干净的新数据库,看看问题是否仍然存在。很可能您已经删除了代码库中的所有迁移,但您的数据库仍然有更早的记录
-
我已经多次删除数据库并多次使用新生成的数据库。所以这不是问题
-
类似问题(不同原因):stackoverflow.com/q/23666716/176877
标签: entity-framework asp.net-mvc-4 entity-framework-migrations