【问题标题】:Install a Service as x64将服务安装为 x64
【发布时间】: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


【解决方案1】:

我尝试了 Alex 和 Jacob Seleznev 的解决方案,它们都有效。我发现雅各布link 的 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.

share|edit|flag 于 2011 年 7 月 23 日 3:09 回答 Greg Sansom 6,5781335

【讨论】:

    【解决方案2】:

    我的猜测是您使用的是 32 位 InstallUtil,它只能安装为 32 位,您需要使用 64 位 Installutil,如 here 所述

    【讨论】:

    • 默认情况下,InstallUtil 的 32 位版本可以在 C:\Windows\Microsoft.NET\Framework\v4.0.30319 中找到,64 位版本可以在 C:\Windows\Microsoft.NET\Framework64\v4.0.30319 中找到。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-28
    • 2018-03-10
    • 2015-06-21
    相关资源
    最近更新 更多