2013-03-06 69 views
1

我使用Visual Studio 2010在64位系統上開發了一項服務。該服務只是一個訪問輔助庫中Start和Stop方法的框架。該庫訪問64位COM對象,並且必須構建爲x64。 COM對象是一個dll,它是作爲x64單獨構建的並在64位環境中進行測試。我有一個安裝程序,它可以設置項目並通過自定義操作安裝服務。將服務安裝爲x64

我用繞過服務的測試應用程序調試代碼,所以我可以確認服務正在訪問的庫是否正常工作。

我遇到的問題是安裝時出現BadImageFormatException。我正在使用x64目標平臺的安裝程序。如果我創造一切條件爲64,我得到以下信息:

Error 1001. Exception occured while initializing the installation: System.BadImageFormatException. Could not load file or assembly... or one of its dependencies. An attempt was made to load a program with an incorrect format. 

如果我全力打造集作爲任何CPU,工程安裝,服務可以訪問的庫,但COM對象的服務不能被發現。如果我刪除安裝服務的自定義操作,安裝也將工作。如果我然後嘗試使用installutil手動安裝該服務,則會收到與上面相同的錯誤消息。

下面是我在服務中使用的庫的列表。

using System; 
using System.Diagnostics; 
using System.ServiceProcess; 
using System.Text; 
using System.Threading; 
using MAPIMail; 
using MAPIMail.Logging; 

請注意,MAPIMail項目正在構建爲x64。

有沒有人有一個想法,爲什麼我不能像X64系統上的任何CPU一樣安裝好服務時爲什麼不能特別安裝服務。我感謝任何和所有的建議。

+1

精確[複製](http://stackoverflow.com/questions/5475820/system- badimageformatexception-when-installing-program-from-vs2010-installer-pro)_System.BadImageFormatException當從VS2010安裝程序安裝程序Project_ – 2013-03-06 21:02:51

+0

感謝您指出這一點,Jacob。我確實選擇了正確的先決條件,但我正在調查Greg Sansom的第二個回答,看看它是否能解決我的問題。 – Tim 2013-03-06 21:27:17

+1

祝你好運。發佈答案,無論哪個工作。 – 2013-03-06 21:28:39

回答

2

我都嘗試亞歷克斯和雅各謝列茲尼奧夫的解決方案,他們都工作。我發現來自Jacob's link的Greg Sansom提供的第二個答案提供了最佳解決方案。爲了幫助他人,我複製了他的答案如下:

如果您的安裝程序正在安裝64位dll,則會發生這種情況。該 以下是從MSDN複製:如果添加了64位管理的自定義操作來安裝項目

,該 Visual Studio的生成過程中嵌入了一個32位版本的 InstallUtilLib.dll進入MSI作爲InstallUtil。反過來,加載32位的 .NET Framework以運行64位受管自定義操作,並且 會導致BadImageFormatException異常。

解決方法是將32位InstallUtilLib.dll替換爲64位版本的 。

1. Open the resulting .msi in Orca from the Windows Installer SDK. 
2. Select the Binary table. 
3. Double click the cell [Binary Data] for the record InstallUtil. 
4. Make sure "Read binary from filename" is selected and click the Browse button. 
5. Browse to %WINDIR%\Microsoft.NET\Framework64\v2.0.50727. 
6. The Framework64 directory is only installed on 64-bit platforms and corresponds to the 64-bit processor type. 
7. Select InstallUtilLib.dll. 
8. Click the Open button. 
9. Click the OK button. 

分享|編輯|旗3:09格雷格 - 桑塞姆回答7月23日'11 6,5781335

2

我的猜測是,您使用的是32位InstallUtil只能安裝32位,您需要使用64位Installutil描述here

+0

默認情況下,可在C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319中找到32位版本的'InstallUtil',並在C:\ Windows \ Microsoft中找到64位版本.NET \ Framework64 \ v4.0.30319'。 – 2017-11-17 16:16:38