Reputation: 4002
When I am trying to run the Debugger for Visual Studio 2010 and for Visual Studio 2012, I get the below error:
Error while trying to run project: Could not load file or assembly 'MyProject' or one of its dependencies. An attempt was made to load a program with an incorrect format.
But when I go to the x64/Debug folder and run the EXE directly, it opens fine.
I've tried disabling the project that contains the 32-bit references, but it still gives me the error even when all the other projects are 64-bit (set through Configuration Manager)
Edit #1: In 32-bit compilation mode, I set everything to Any CPU
except the Main startup project to x86 and it runs Debug Mode fine. When I go to 64-bit, and do the same but change Main startup project to x64 it gives the above error. I tried setting all Target values to x64, but still nothing.
Upvotes: 2
Views: 9533
Reputation: 11
I've had the same problem with debugging x64 empty console application. Application ran without debugging in any case, but debugging was working only with x86/AnyCPU target platform (32 bit process), but with x64 I was getting:
Error while trying to run project: Could not load file or assembly 'ConsoleApplication1' or one of its dependencies. An attempt was made to load a program with an incorrect format.
My solution was to turn off Project -> Properties -> Debug -> Enable the Visual Studio hosting process
Upvotes: 1
Reputation: 141
I can confirm that Everlight's trick does fix the problem.
My situation was as following:
The fix is: Project > {project name} Properties... > Build > Platform target. It should be "Any CPU" by default. Change it to x86 or x64.
I hope this helps someone.
Upvotes: 0
Reputation: 451
The following is my fix to this problem:
In Visual Studio 2010 for c# in the solution explorer right click on each project -> properties -> Build. Change the Platform and the Platform target to Any CPU for 64-bit, or x86 for 32-bit.
I also had a little reference problem after that, simply remove and re-add any references that cause errors.
If you already found a solution to this problem, please post one! Thank you.
Upvotes: 4