I can't enable EF migrations!
Using the package manager console, it throws the following:
PM> Enable-Migrations
System.BadImageFormatException: Could not load file or assembly 'MyApp' or one of its dependencies. Index not found. (Exception from HRESULT: 0x80131124)
File name: 'MyApp' ---> System.BadImageFormatException: Index not found. (Exception from HRESULT: 0x80131124)
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, Func2 noType, Func
3 multipleTypes, Func3 noTypeWithName, Func
3 multipleTypesWithName)
at System.Data.Entity.Migrations.Design.ToolingFacade.GetContextTypeRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Could not load file or assembly 'MyApp' or one of its dependencies. Index not found. (Exception from HRESULT: 0x80131124)
Also:
1. My default project (in the PM CONSOLE) is 'MyApp'
2. The solution only has 'MyApp'
3. The class inheriting from DbContext is in 'MyApp.Models'
4. I also tried creating a new solution and then copy pasted all classes to it and it threw the same error
What is happening?
I once enabled migrations in this project in the past, but two days later I deleted all migration stuff from it because it wasn't necesary. But now I really need them
I just had the same problem.
The reason for the System.BadImageFormatException
was because I had a dependency on an x64 DLL (Magick.NET-x64.dll
in my case). Forcing the project to build in 32-bit solved it.
Hopefully this helps someone else.
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.
found at: http://entityframework.codeplex.com/discussions/438488
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With