[英]Install a Service as x64
我使用Visual Studio 2010在64位系統上開發了一項服務。該服務只是一個訪問輔助庫中的Start和Stop方法的框架。 該庫訪問64位COM對象,並且必須構建為x64。 COM對象是一個單獨構建為x64並在64位環境中測試的DLL。 我有一個安裝程序,用於設置項目並通過自定義操作安裝服務。
我使用繞過服務的測試應用程序調試代碼,因此我可以確認服務正在訪問的庫是否正常工作。
我遇到的問題是安裝時出現BadImageFormatException。 我正在使用目標平台為x64的安裝程序。 如果我將所有內容構建為x64,我會收到以下消息:
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作為x64系統上的任何CPU安裝服務。 我感謝任何和所有的建議。
我嘗試了Alex和Jacob Seleznev的解決方案,他們都工作了。 我發現第二個答案,由Greg Sansom,雅各布的鏈接提供了最好的解決方案。 為了幫助別人,我在下面復制了他的答案:
如果您的安裝程序正在安裝64位dll,則會發生這種情況。 從MSDN復制以下內容:
如果將64位托管自定義操作添加到安裝項目,則Visual Studio生成過程會將32位版本的InstallUtilLib.dll作為InstallUtil嵌入到MSI中。 反過來,加載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.
分享|編輯|標志回答2011年7月23日3:09 Greg Sansom 6,5781335
我的猜測是你使用的32位InstallUtil只能安裝為32位,你需要使用這里描述的64位Installutil
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.