[英]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: 当我尝试运行Visual Studio 2010和Visual Studio 2012的调试器时,我收到以下错误:
Error while trying to run project: Could not load file or assembly 'MyProject' or one of its dependencies.
尝试运行项目时出错:无法加载文件或程序集“MyProject”或其依赖项之一。 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. 但是当我转到x64 / Debug文件夹并直接运行EXE时,它打开正常。
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) 我已经尝试禁用包含32位引用的项目,但即使所有其他项目都是64位(通过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. 编辑#1:在32位编译模式下,我将所有内容设置为除了主启动项目之外的
Any CPU
到x86,它运行调试模式正常。 When I go to 64-bit, and do the same but change Main startup project to x64 it gives the above error. 当我转到64位,并执行相同但将主启动项目更改为x64时,它会出现上述错误。 I tried setting all Target values to x64, but still nothing.
我尝试将所有Target值设置为x64,但仍然没有。
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. 在解决方案资源管理器中的c#Visual Studio 2010中,右键单击每个项目 - > properties - > Build。 Change the Platform and the Platform target to Any CPU for 64-bit, or x86 for 32-bit.
将Platform 和 Platform目标更改为64位的任何CPU,或32位的x86。
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. 我可以确认Everlight的技巧可以解决问题。
My situation was as following: 我的情况如下:
The fix is: Project > {project name} Properties... > Build > Platform target. 修复方法是:项目> {项目名称}属性...>构建>平台目标。 It should be "Any CPU" by default.
它应该是默认的“任何CPU”。 Change it to x86 or x64.
将其更改为x86或x64。
I hope this helps someone. 我希望这可以帮助别人。
I've had the same problem with debugging x64 empty console application. 调试x64空控制台应用程序时遇到了同样的问题。 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:
在任何情况下,应用程序都在没有调试的情况下运行,但是调试仅适用于x86 / AnyCPU目标平台(32位进程),但是使用x64我得到了:
Error while trying to run project: Could not load file or assembly 'ConsoleApplication1' or one of its dependencies.
尝试运行项目时出错:无法加载文件或程序集“ConsoleApplication1”或其依赖项之一。 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 我的解决方案是关闭Project - > Properties - > Debug - >启用Visual Studio托管过程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.