Ho un progetto impostato su x64 (sta utilizzando alcuni pacchetti Nuget solo a 64 bit). Tutto gira e distribuisce bene, ma provare a eseguire l'EF enable-migrations
nella console di Gestione pacchetti mi dà un System.BadImageFormatException
. L'eccezione completo:enable-migrations in x64 Project ottiene System.BadImageFormatException
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.
Nota: ho rimosso il nome del progetto dal messaggio di errore, sia per rendere questo più facile da Google e perché è irrilevante a questo problema.
È necessario modificare la piattaforma del progetto targetizzato e le sue dipendenze in x86 o Qualsiasi CPU. La modifica del percorso di output non è sufficiente. L'eccezione BadImageFormatException viene creata quando PM Console tenta di caricare l'assembly x64 nel processo a 32 bit di Visual Studio.(Sto solo ripetendo il commento sul bug di MS nella segnalazione bug.) – Epstone
La modifica della directory bin non si applica ai progetti ASP.NET - c'è solo una directory bin in cui tutto va. Questo è un problema con "Enable-Migrations" che funziona solo con gli assembly x86. Cambiare il tipo di output del progetto in 'AnyCPU' fa il trucco. – Phil