BadImageException using update-database

2019-08-05 00:48发布

问题:

I have an assembly with an EF 5.0 (target framework 4.0) migrations in it.

When I open the package management console and type 'update-database' I get an BadImageException. (note: I have one c++ native lib in the solution).

I have read several post regarding this and I tried:

  1. All projects have x64 target platform
  2. Solution platform is x64, all projects have x64 as configuration
  3. No warnings during build

But...when I added a console app, using DBMigrator class the migration works fine!

What happens ?

(update)

It seems that when using the Package Management Console and use 'update-database', it uses an .exe in the package root of EF / tools, called 'migrate.exe'. This .exe is 32bit and is not able to load 64 bit assemblies! Check http://msdn.microsoft.com/en-us/data/jj618307.aspx)

Using VS2013, Update 1.

The exception detail:

PM> update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
System.BadImageFormatException: Could not load file or assembly 'Progis.Kim.DataAccess.Systeem' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'Progis.Kim.DataAccess.Systeem'
   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 filter, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = Progis.Kim.DataAccess.Systeem
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Progis.Kim.DataAccess.Systeem | Domain ID: 28
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/WS/ProgisKIM/Development/Progis/Progis.Kim.DataAccess.Systeem/bin/x64/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\WS\ProgisKIM\Development\Progis\Progis.Kim.DataAccess.Systeem\tmpEC23.tmp
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/WS/ProgisKIM/Development/Progis/Progis.Kim.DataAccess.Systeem/bin/x64/Debug/Progis.Kim.DataAccess.Systeem.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

Could not load file or assembly 'Progis.Kim.DataAccess.Systeem' or one of its dependencies. An attempt was made to load a program with an incorrect format.
PM>