简体   繁体   English

尝试在调试模式下运行项目时出错,但如果我运行EXE文件则有效

[英]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 Solution was created in Visual Studio 2012 running on x86 (32-bit) Windows 7. 解决方案是在运行x86(32位)Windows 7的Visual Studio 2012中创建的。
  • After upgrading to x64 (64-bit) Windows 8, I could no longer debug the solution in the same Visual Studio version. 升级到x64(64位)Windows 8后,我无法再在同一个Visual Studio版本中调试解决方案。 However I could run the compiled exe file manually. 但是,我可以手动运行已编译的exe文件。
  • 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." 我得到的错误是:“尝试运行项目时出错:无法启动程序'path-to-solution-exe-file'。发生了未知的Windows Web服务基础结构错误。”

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.

相关问题 尝试在调试模式下运行项目时出现“找不到文件...\\bin\\Debug”错误 - "Could not find file...\bin\Debug" error when trying to run project at debug mode EXE 文件从 obj\Debug 中消失,无法运行项目 - The EXE file is disappear from obj\Debug and cannot run the Project 尝试运行项目时出错:访问被拒绝 - Error while trying to run project: Access is denied 尝试在VS 2012中运行项目时出错 - Error while trying to run project in VS 2012 WPF Do.NET 应用程序将在调试模式下运行,但 .EXE 将不会运行 - WPF DotNET Application will run in debug mode, but .EXE will not run 尝试运行没有dll的exe文件时,如何显示错误消息? - How can I show an error message when trying to run an exe file without its dlls? Selenium 代码在调试模式下工作,但在运行模式下失败 - Selenium Code works in debug mode but fails in run mode 错误尝试运行项目时:无法加载文件或程序集“Windowsformapplication1”或其依赖项之一? - Error While trying to run the project: could not load file or assembly 'Windowsformapplication1' or one of its dependencies? 尝试运行项目时出错:模块应包含程序集清单 - Error while trying to run project:The module was expected to contain an assembly manifest 尝试运行项目时出错。 该地址对此上下文无效 - Error while trying to run project. The address is not valid for this context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM