【发布时间】:2013-03-14 01:22:13
【问题描述】:
我使用 Visual Studio 2010 在 64 位系统上开发了一项服务。该服务只是一个框架,它可以访问辅助库中的 Start 和 Stop 方法。该库访问 64 位 COM 对象,并且必须构建为 x64。 COM 对象是一个 dll,它作为 x64 单独构建并在 64 位环境中测试。我有一个安装程序,可以设置项目并通过自定义操作安装服务。
我使用绕过服务的测试应用程序调试代码,因此我可以确认服务正在访问的库工作正常。
我遇到的问题是安装时出现 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 系统上像 Any CPU 一样安装时,我不能将服务专门安装为 x64。我感谢任何和所有建议。
【问题讨论】:
-
Exact duplicate 从 VS2010 安装程序项目安装程序时出现 System.BadImageFormatException
-
感谢您指出这一点,雅各布。我确实选择了正确的先决条件,但我正在研究 Greg Sansom 的第二个答案,看看它是否能解决我的问题。
-
祝你好运。发布答案,无论哪个有效。
-
@Jacob,就是这样。如果您想通过该帖子的链接回答问题,我会感谢您。我利用了格雷格给出的步骤。谢谢。
标签: c# visual-studio-2010 exception windows-installer