我使用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一樣安裝好服務時爲什麼不能特別安裝服務。我感謝任何和所有的建議。
精確[複製](http://stackoverflow.com/questions/5475820/system- badimageformatexception-when-installing-program-from-vs2010-installer-pro)_System.BadImageFormatException當從VS2010安裝程序安裝程序Project_ – 2013-03-06 21:02:51
感謝您指出這一點,Jacob。我確實選擇了正確的先決條件,但我正在調查Greg Sansom的第二個回答,看看它是否能解決我的問題。 – Tim 2013-03-06 21:27:17
祝你好運。發佈答案,無論哪個工作。 – 2013-03-06 21:28:39