Trying to run EF Code first Migrate.exe tool on production environment failed

4

I'm using EntityFramework version 6.1.3.

I copied migrate.exe from EntityFramework version 6.1.3 package tool folder to bin folder of my website.

My web site is compiled and published to production environment with x86 CPU and target framework 4.5.1

I run the following command:

D:\Sites\MatrixPortal\bin>migrate.exe d:\sites\MatrixPortal\bin\MatrixPortal.BL.dll /startUpDirectory="d:\Sites\MatrixPortal\bin" /startUpConfigurationFile="d:\Sites\MatrixPortal\Web.config"

and i get the following error:

ERROR: Could not load file or assembly 'd:\sites\MatrixPortal\bin\MatrixPortal.BL' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

EDIT:

when i try this:

migrate MatrixPortal.BL.dll /verbose

i get other error:

System.BadImageFormatException: Could not load file or assembly 'MatrixPortal.BL' or one of its dependencies. An attempt was made to load a program with an incorrect format. File name: 'MatrixPortal.BL' 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.BaseRunner.FindConfiguration() at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run() at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) at System.Data.Entity.Migrations.Console.Program.Run() at System.Data.Entity.Migrations.Console.Program.Main(String[] args)

=== Pre-bind state information === LOG: DisplayName = MatrixPortal.BL (Partial) WRN: Partial binding information was supplied for an assembly: WRN: Assembly Name: MatrixPortal.BL | Domain ID: 2 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:///D:/Sites/MatrixPortal/bin/ LOG: Initial PrivatePath = NULL Calling assembly : EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\guy_b\AppData\Local\Temp\tmpC402.tmp LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\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:///D:/Sites/MatrixPortal/bin/MatrixPortal.BL.DLL. ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

ERROR: Could not load file or assembly 'MatrixPortal.BL' or one of its dependencies. An attempt was made to load a program with an incorrect format.

also tried this: http://www.azurefromthetrenches.com/command-line-entity-framework-code-first-migrations/

and created a file called Redirect.config with the following content:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
                                <bindingRedirect oldVersion="0.0.0-6.1.3" newVersion="6.1.3" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

but got the same error as above :(

entity-framework
ef-migrations
asked on Stack Overflow Dec 20, 2015 by Guy Bertental • edited Dec 22, 2015 by Guy Bertental

2 Answers

1

SOLVED!

I've Published the web site project with x86 target cpu, and apparently it wasn't really x86, i don't know why, maybe a bug?

After changing Publish to any cpu it worked. i was able to run migrate.exe without an error using the following arguments:

migrate.exe MatrixPortal.BL.dll /verbose /startUpDataDirectory="D:\Sites\MatrixPortal" /startUpConfigurationFile="D:\Sites\MatrixPortal\Web.config"
answered on Stack Overflow Dec 28, 2015 by Guy Bertental
1

In my case I got the error because I wrote migrate .\MyAssembly.dll instead of migrate MyAssembly.dll.

See Common Problems documentation section.

answered on Stack Overflow Apr 19, 2019 by Der_Meister • edited Apr 19, 2019 by Der_Meister

User contributions licensed under CC BY-SA 3.0