System.BadImageFormatException:(从installutil.exe)

问题描述:

我试图安装使用InstallUtil.exe Windows服务,并正在错误消息System.BadImageFormatException:(从installutil.exe)

System.BadImageFormatException: Could not load file or assembly ' {xxx.exe} ' or one of its dependencies. An attempt was made to load a program with an incorrect format.

是什么让无法加载文件或程序?


编辑:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe C:\xxx.exe Microsoft (R) .NET Framework Installation utility Version 4.0.30319.1 Copyright (c) Microsoft Corporation. All rights reserved.

Exception occurred while initializing the installation: System.BadImageFormatException: Could not load file or assembly 'file:///C:\xxx.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format..

确保最新的框架(你编译你的应用程序中的一个)是:(不可由OP)全部消息从DUP越来越方式更多的点击[为googleability]提取首先在PATH中。这解决了我的问题。这里找到:http://www.issociate.de/board/post/280574/Installutil_System.BadImageFormatException.html

+0

该链接似乎已消失。不太奇怪,但。 6年前。 – 2014-10-30 19:41:44

+2

这是在Archive.org https://web.archive.org/web/20100527204545/http://www.issociate.de/board/post/280574/Installutil_System.BadImageFormatException.html – Epaga 2014-11-14 08:24:00

的完整性一些更详细的情况下,它可以帮助别人......

请注意,此例外,这些天正在试图加载32位特定(/platform:x86)DLL到的最常见原因一个64位或反之亦然的过程(即将一个64位特定的(/platform:x64)DLL加载到32位的进程中)。如果你的platform是非特定的(/platform:AnyCpu),这不会出现(假设没有引用的依赖关系是错误的位)。

换句话说,运行:

%windir%\Microsoft.NET\Framework\v2.0.50727\installutil.exe

或:

%windir%\Microsoft.NET\Framework64\v2.0.50727\installutil.exe

将无法​​正常工作(在其他框架版本替代:v1.1.4322(仅限32位,所以这个问题不会出现)和v4.0.30319,如上所述)。

显然,正如其他答案中所述,您还需要运行的installutil的.NET版本号≥>(最好是=)您正在运行安装程序的EXE/DLL文件。

最后,请注意in Visual Studio 2010, the tooling will default to generating x86 binariesrather than Any CPU as previously)。

Complete details of System.BadImageFormatException(说唯一的原因是不匹配的咬人真的是一个过分简单化!)。

下安装程序的另一个原因BadImageFormatExceptionin Visual Studio 2010, the default .vdproj Install Project type generates a 32-bit InstallUtilLib shim, even on an x64 system(搜索“64位管理的自定义操作抛出一个异常System.BadImageFormatException”页面上)。

好的,这是我的问题,而且,固定它的东西似乎与上述非常相关。

我正在使用Visual Studio 2010 Express。我写了一个测试服务,没有做任何事情。这只是后来的实践。

我写的服务,并尝试使用installutil.exe安装它,并得到了以下错误:

System.BadImageFormatException: Could not load file or assembly '{filename.exe}' or one of its dependencies. An attempt was made to load a program with an incorrect format.

到目前为止一样的原作者。

Ruben's observation以上关于Visual Studio 2010的32位输出是这里的救世主。

我使用的是installutil.exe的64位版本,当然,Visual Studio 2010 build的输出是32位的。只需要在这里添加一些额外的值,您可以在C:\ Windows \ Microsoft.NET \ framework文件夹中找到最新的.NET框架的32位版本和关联的installutil.exe。使用installutil.exe的这个版本解决了我的问题;该服务安装顺利!

我希望这可以帮助别人。

我认为您使用的是64位版本的工具来安装32位应用程序。 我今天也遇到过这个问题,并使用这个框架路径来迎合。

C:\ WINDOWS \ Microsoft.NET \框架\ v4.0.30319

,它应该安装您的32位应用程序就好了。

感谢

萨钦卡利亚

在情况下,它可以帮助任何人,我能够修复使用this answer到类似的问题,这同样的异常,但我没有使用installutil.exe得到的异常。

我有同样的问题。我使用标准命令执行。它正在调用X64对X86测试。我需要指定X86而不是nunit-runner的X64版本。

总结,为了在64位系统上成功安装64位服务,Build和Project \ Build \ Platform必须设置为x64。