BadImageFormatException is one exception thrown from the execution engine when you are trying to load one assembly compiled for a specific platform in another platform.
Example A
- project A, compiled as X86
- project B, compiled as X86
- executable, compiled in X86
all work fine in x86 machine and x64 operating system
Example B
- project A, compiled as X86
- project B, compiled as X86
- executable, compiled in AnyCPU
all work fine in x86 operating system
this throw exception in x64 OS (executable is in AnyCPU so it's run on x64 engine, so can't load x86 dll's)
Example C
- project A, compiled as AnyCPU
- project B, compiled as x86
- executable, compiled in AnyCPU
all work fine in x86 operating system
this throw exception in x64 OS (executable is in AnyCPU so it's run on x64 engine, so can't load x86 dll's)
Example D
- project A, compiled as AnyCPU
- project B, compiled as x86
- executable, compiled in x86
all work fine in x86 operating system
all work fine in x64 operating system
the exe is compiled specifically for x86 platform, so also in x64 machine run under x86 mode.
Conclusion
Visual studio run projects in OS configuration, so in debug mode if you don't have a specific x86 configuration for starting project and try to execute an x86 referenced dll it will fail