简体   繁体   中英

Error while trying to run project in debug mode, but works if I run the EXE file

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.

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.

I can confirm that Everlight's trick does fix the problem.

My situation was as following:

  • The Solution was created in Visual Studio 2012 running on x86 (32-bit) Windows 7.
  • After upgrading to x64 (64-bit) Windows 8, I could no longer debug the solution in the same Visual Studio version. However I could run the compiled exe file manually.
  • The error I was getting was: "Error while trying to run project: Unable to start program 'path-to-solution-exe-file'. Unknown Windows web-services infrastructure error has occurred."

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM