I have two projects, ProjectA
and ProjectB
. ProjectB
is a console application, which depends on ProjectA
. Yesterday, everything was working fine, but suddenly today when I run ProjectB
I get this:
BadImageFormatException was unhandled:
Could not load file or assembly 'ProjectA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Both are just regular projects, with no dependencies on any other non-.Net projects. Both are fully .Net - there is no native code, and no P/Invoke. I have other projects which depend on ProjectA
and still work just fine.
Things I have tried:
But I still get the same error. I have no idea what I did to cause this, nor how to fix it. Any ideas?
SOLUTION: If you are on IIS7, Right Click/ Advanced Settings on the Specific Application Pool of the website and select True on Enable 32-Bit Applications. It should work.
“An attempt was made to load a program with an incorrect format.” That means that the assembly, which was to be loaded, was in an unexpected format. The format, in this case, refers most likely to the 64-bit build of an application being deployed to IIS, which is being run in 32-bits.
A System. BadImageFormatException error often occurs when a 64-bit assembly is opened by a 32-bit application. In this case, Visual Studio is a 32-bit application and the Design view is attempting to load a 64-bit assembly. Visual Studio assemblies are located in the project references tree.
There are some workarounds for this issue: The dll file may not be in /bin folder. Just copy the dll file to /bin folder or set this preference Copy Local = True from Visual Studio. If the problem persists, check if the version of the assembly that is referenced is different than the version it is looking for.
I am pretty sure you're having a 32-bit / 64-bit conflict. It sounds like your main project might be set to 32-bit while the class its referencing is set to 64-bit. Try looking at this SO question and this one too. Between the two of them, you should be able to figure out your problem.
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