使-迁移的64项目得到System.BadImageFormatException
我必须设置为64位项目(它使用了一些的NuGet包只有64位)。一切运行,并部署了罚款,但试图运行EF的启用-迁移
的软件包管理器控制台让我一个 System.BadImageFormatException
。完整的异常:
I have a project set to x64 (it's using some Nuget packages that are 64-bit only). Everything runs and deploys fine, but trying to run EF's enable-migrations
at the Package Manager Console gets me a System.BadImageFormatException
. The full exception:
PM> enable-migrations
System.BadImageFormatException: Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name:
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(String name)
at System.Data.Entity.Migrations.Design.ToolingFacade.GetContextTypeRunner.Run()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.GetContextType(String contextTypeName)
at System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(String contextTypeName)
at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format.
注:我已经删除从错误信息的项目名称,这样既可以使这更容易谷歌和,因为它是不相关的这个问题。
Note: I've removed the project name from the error message, both to make this easier to google and because it's irrelevant to this problem.
的问题是,启用-迁移
命令似乎有一个硬codeD路径其中,在EF 查找项目建成的DLL /斌/调试
,无论实际的构建路径是什么。当你改变一个项目到x64,Visual Studio中悄悄地改变你的项目的构建路径 /斌/ X64 /调试
- 而EF一直在寻找 /箱/调试
。导致此模糊System.BadImageFormatException。 另外这里讨论了codePLEX 。
The problem is that the enable-migrations
command appears to have a hard-coded path where EF looks for built DLLs of your project at /bin/Debug
, no matter what the actual build path is. When you change a Project to x64, Visual Studio quietly changes your project's build path to /bin/x64/Debug
- while EF keeps looking in /bin/Debug
. That causes this vague System.BadImageFormatException. Also discussed here on Codeplex.
这是无害的,只是改变你的项目构建路径 /斌/调试
和神奇,一切都开始喜欢它的工作是应该。
It's harmless to just change your Project build path to /bin/Debug
and magically, everything begins working like it's supposed to.
错误存在至多并包括EF 6.1.0。 错误报告公布。
Bug exists up to and including EF 6.1.0. Bug report posted.
更新:微软已决定不打扰修复bug,关闭,wontfix,因为有解决方法。 pretty的不良行为。
Update: Microsoft has decided not to bother fixing the bug, closed as wontfix, because a workaround exists. Pretty bad behavior.