我有两个项目,项目a和项目b。projecb是一个控制台应用程序,它依赖于ProjectA。昨天,一切都很好,但今天突然当我运行ProjectB时,我得到了这个:

BadImageFormatException未处理: 无法加载文件或程序集“ProjectA, Version=1.0.0.0, Culture=中性,PublicKeyToken=null”或其依赖项之一。试图加载格式不正确的程序。

两者都只是常规项目,不依赖于任何其他非。网络项目。两者都是完全的。net -没有本机代码,也没有P/Invoke。我有其他项目依赖于ProjectA,仍然工作得很好。

我尝试过的事情:

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.

但还是得到相同的错误。我不知道我做了什么导致了这一切,也不知道该怎么补救。什么好主意吗?

我从64位系统上的32位非托管DLL调用函数。我得到的是:

BadImageFormatException:试图加载格式不正确的程序。(异常来自HRESULT: 0x8007000B)

首先,我把我的项目设置为任何CPU平台,所以我把它们都改为x86,但这个错误仍然发生。这是我知道的唯一解决办法。

dll没有损坏,因为我可以将它们与其他程序一起使用(我没有源代码)。我想也许它没有找到一个依赖,但我检查了一下,它们都在那里。另外,它不会在这种情况下抛出DllNotFoundException吗?

我还能做什么?在您说“改用64位非托管DLL”之前,请允许我指出没有一个DLL。;)