Enable-Migrations encounter "System.BadImageFormatException: Could not load file or assembly 'EnvDTE, ...'The module was expected to contain an assembly manifest.

Topics: EF Designer, EF Runtime, General
Mar 30, 2013 at 1:15 AM
I used VS2010 under Win7(x64 ), installed Nuget and install the EF Package. And can read and write DB successful. But I want to Enable Migration used the Nuget Package Manager Console, then I will encounter the error as below:
PM> enable-migrations
System.BadImageFormatException: Could not load file or assembly 'EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The module was expected to contain an assembly manifest.
File name: 'EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.BadImageFormatException: The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)
at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)


Could not load file or assembly 'EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The module was expected to contain an assembly manifest.

I try to copy the "Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\EnvDTE.dll" to the project bin folder, but it dosen't work

If anyone help me?
Jun 4, 2013 at 10:14 AM
Edited Jun 4, 2013 at 11:35 AM
Hi,

i ran into the same issue.

I had a Contracts component and a DAL component referencing the EF and Contracts component.

E.g.
Contracts.dll
DAL.dll -> Contracts.dll

Due to a dependency of a Oracle component in my DAL i had to change my platform target to x64.

I finally does following process:
  1. Checked my dependencies in Contracts.dll and DAL.dll.
  2. Removed unneeded dependencies.
  3. Close my solution.
  4. Delete all output (bin\Debug or bin\Release) folders
  5. Start Solution.
  6. Set DAL project as Startup Project.
  7. Enter under package manager console: Enable-migrations
Done.

Hope it helps.

Update:
I finally realized that it depends of the current output folder of your project.
When changing the target platform to x64 the output folder also changes to bin\x64\Debug.
This seemed to be a problem for the enable-migrations cmdlet.
After changing the output folder back to bin\Debug for a x64 platform build everything works fine.