微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

entity-framework – 无法启用 – 迁移.引发System.BadImageFormatException:无法加载文件或程序集

我无法启用EF迁移!

使用包管理器控制台,它会抛出以下内容

PM>启用的迁移
System.BadImageFormatException:无法加载文件或程序集“MyApp”或其依赖项之一.索引未找到. (HRESULT异常:0x80131124)
文件名:’MyApp’—> System.BadImageFormatException:找不到索引. (HRESULT异常:0x80131124)
   在System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark& stackMark,IntPtr pPrivHostBinder,Boolean throwOnFileNotFound,Boolean forIntrospection,Boolean suppressSecurityChecks)
   在System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName,Boolean suppressSecurityChecks)
   在System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef,RuntimeAssembly reqAssembly,Boolean suppressSecurityChecks)
   在System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,Boolean forIntrospection)
   在System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,Boolean forIntrospection)
   在System.Reflection.Assembly.Load(String assemblyString)
   在System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.LoadAssembly()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindType [TBase](String typeName,Func2 filter,Func2 noType,Func3 multipleTypes,Func3 noTypeWithName,Func3 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位构建解决了它.

>选择您的WebProject
>转到“属性
>选择“构建”选项卡
>更改平台目标:从x64到任何cpu

希望这有助于其他人.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐