2008-11-27 47 views
82

我試圖安裝使用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..

回答

14

確保最新的框架(你編譯你的應用程序中的一個)是:(不可由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

125

的完整性一些更詳細的情況下,它可以幫助別人......

請注意,此例外,這些天正在試圖加載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」頁面上)。

5

好的,這是我的問題,而且,固定它的東西似乎與上述非常相關。

我正在使用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的這個版本解決了我的問題;該服務安裝順利!

我希望這可以幫助別人。

8

我認爲您使用的是64位版本的工具來安裝32位應用程序。 我今天也遇到過這個問題,並使用這個框架路徑來迎合。

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

,它應該安裝您的32位應用程序就好了。

感謝

薩欽卡利亞

1

在情況下,它可以幫助任何人,我能夠修復使用this answer到類似的問題,這同樣的異常,但我沒有使用installutil.exe得到的異常。

0

我有同樣的問題。我使用標準命令執行。它正在調用X64對X86測試。我需要指定X86而不是nunit-runner的X64版本。

0

總結,爲了在64位系統上成功安裝64位服務,Build和Project \ Build \ Platform必須設置爲x64。

相關問題