我有两个项目,项目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.

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


当前回答

在我的例子中,错误是系统。BadImageFormatException:无法加载文件或程序集'vjslib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'或其依赖项之一。

从这里安装vjredist 64解决了这个问题。

其他回答

在我的案例中,将IIS Express Bitness从“默认”更改为“x86”有帮助。

我所有的项目都以“x86”作为平台目标。

我在Visual Studio 2015中运行单元测试(xunit)时遇到了这个问题,并遇到了以下修复:

Menu Bar -> Test -> Test Settings -> Default Processor Architecture -> X64

可能是你的网站部署到服务器后遇到的问题。

然后将应用程序池调整为启用32位应用程序。

步骤

打开IIS管理器 单击应用程序池 选择您正在使用的任何应用程序池 从右侧窗格,单击高级设置… “启用32位应用程序”设置为“True”

您正在尝试从cmd运行您的.exe文件吗?这是我的错。只需双击运行.exe文件。如果是Windows 8.1/Windows Server 2012 R2 x64的。net Core SCD。

我也有同样的问题。项目B在我的案例中是一个。net核心类库,它有一个Nuget“Microsoft.Management”。安装基础设施”。错误在于我把我的B项目叫做MI。我将项目名称改为其他名称,突然之间一切都恢复正常了。