无法加载文件或程序集...尝试加载格式不正确的程序 (System.BadImageFormatException) [英] Could not load file or assembly ... An attempt was made to load a program with an incorrect format (System.BadImageFormatException)
问题描述
我有两个项目,ProjectA
和 ProjectB
.ProjectB
是一个控制台应用程序,它依赖于 ProjectA
.昨天,一切正常,但今天突然当我运行 ProjectB
时,我得到这个:
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 未处理:
无法加载文件或程序集ProjectA,版本=1.0.0.0,文化=中性,PublicKeyToken=null"或其依赖项之一.试图加载格式不正确的程序.
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.
两者都只是常规项目,不依赖于任何其他非 .Net 项目.两者都是完全 .Net - 没有本机代码,也没有 P/Invoke.我还有其他依赖于 ProjectA
的项目,但仍然可以正常工作.
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.
我尝试过的事情:
- 确保两个项目都设置为任何 CPU",并选中 build 复选框.他们是.
- 确保两个项目都用于相同的目标框架(.Net 4.0 客户端配置文件).
- 在 ProjectB --> References --> ProjectA --> Properties 下,确保 "Copy Local" 设置为 "True" _ (I验证 ProjectA.dll 被正确复制)
- 清理/重建解决方案.我什至尝试手动删除两个项目中的/bin 和/obj 文件夹.
- 重新启动 Visual Studio.重新启动我的电脑.
- 查看存储库的全新副本.
- Make sure both projects are set to "Any CPU," with the build checkbox checked. They are.
- Make sure both projects are for the same Target Framework (.Net 4.0 Client Profile).
- Under ProjectB --> References --> ProjectA --> Properties, make sure "Copy Local" is set to "True" _ (I verified that ProjectA.dll is being copied correctly)
- Clean/Rebuild the solution. I even tried manually deleting the /bin and /obj folders in both projects.
- Restart Visual Studio. Restart my computer.
- Check out an entirely new copy of the repository.
但我仍然遇到同样的错误.我不知道我做了什么导致这个,也不知道如何解决它.有什么想法吗?
But I still get the same error. I have no idea what I did to cause this, nor how to fix it. Any ideas?
推荐答案
我很确定您遇到了 32 位/64 位冲突.听起来您的主项目可能设置为 32 位,而其引用的类设置为 64 位.尝试查看这个问题和这个也是.在他们两个之间,你应该能够弄清楚你的问题.
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.
这篇关于无法加载文件或程序集...尝试加载格式不正确的程序 (System.BadImageFormatException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!