entity-framework - 无法启用迁移。抛出 System.BadImageFormatException : Could not load file or assembly

标签 entity-framework asp.net-mvc-4 entity-framework-migrations

我无法启用 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, Func 2 过滤器,功能 2 noType, Func 3 multipleTypes, Func 3 noTypeWithName, Func 3 multipleTypesWithName)
在 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.我也尝试创建一个新的解决方案,然后将所有类复制粘贴到它,它抛出了同样的错误

怎么了?
过去我曾经在这个项目中启用了迁移,但两天后我删除了其中的所有迁移内容,因为它不是必需的。但现在我真的需要它们

最佳答案

我只是遇到了同样的问题。
System.BadImageFormatException的原因是因为我依赖于 x64 DLL(在我的例子中是 Magick.NET-x64.dll)。强制项目以 32 位构建解决了它。

  • 选择您的 网络项目
  • 转至 属性
  • 选择 构建 标签
  • 更改 平台目标 :来自 x64 任意 CPU

  • 希望这对其他人有帮助。

    关于entity-framework - 无法启用迁移。抛出 System.BadImageFormatException : Could not load file or assembly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16874451/

    相关文章:

    c# - SQL Server CE Code First 迁移问题

    asp.net - 向 User 类添加属性违反了 TContext 类型的约束

    razor - 这里使用哪种算法来哈希密码?

    asp.net - MVC 5 更改主页

    entity-framework - EntityObject 有多重要?

    c# - 如何在 .NET Core 1.0 中使用 Entity Framework 运行 sql 脚本?

    visual-studio-2010 - 如何修复错误 - 项目中不存在目标 "_CopyBinDeployableAssemblies"?

    c# - Entity Framework 代码优先迁移

    c# - EF 中的 GUID COMB 策略

    c# - 未知的 CS1003 错误