无法加载文件或程序集...试图加载一个不正确的程序格式(System.BadImageFormatException)
我有两个项目,项目A
和项目B
。 项目B
是一个控制台应用程序,它依赖于项目A
。昨天,一切都被今天工作正常,但突然当我运行项目B
我得到这样的:
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了未处理:结果
无法加载文件或程序集项目A,版本= 1.0.0.0,文化=中性公钥= 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.
两者都只是常规项目,与其他任何non-.Net项目没有依赖关系。两者都是充分的.Net - 没有提供原生code,没有的P / Invoke。我有依赖于项目A
,仍然工作得很好。
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,与建立的复选框选中。他们是。
- 确保这两个项目都为同一目标框架的(.NET 4.0客户端配置文件)的
- 在项目B - >参考 - >项目A - >属性中,确保的复制本地的设置为真 _ (我验证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?
我是pretty确保你有一个32位/ 64位的冲突。这听起来像,而其类引用设置为64位的主项目可能会被设置为32位。试着寻找这太问题和this它太。他们两个之间,你应该能够找出您的问题。
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.