我尝试使用 InstallUtil.exe 安装 Windows 服务并收到错误消息
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.
什么给出了?
<小时/>编辑:(不是OP)从dup中提取的完整消息获得了更多点击[用于谷歌能力]:
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..
最佳答案
一些更完整的细节,以防它对某人有帮助......
请注意,目前出现此异常的最常见原因是尝试将 32 位特定 (/platform:x86
) DLL 加载到 64 位进程中,反之亦然(即将 64 位特定 (/platform:x64
) DLL 加载到 32 位进程中。如果您的平台
是非特定的(/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 binaries (rather than Any CPU as previously)。
Complete details of System.BadImageFormatException (说唯一的原因是咬合不匹配确实过于简单化了!)。
x64 安装程序下出现 BadImageFormatException
的另一个原因是 in Visual Studio 2010, the default .vdproj
Install Project type generates a 32-bit InstallUtilLib
shim, even on an x64 system (在页面上搜索“64 位托管自定义操作引发 System.BadImageFormatException 异常”)。
关于.net - 系统.BadImageFormatException : Could not load file or assembly (from installutil. exe),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/323140/