Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将服务安装为x64_C#_Visual Studio 2010_Exception_Windows Installer - Fatal编程技术网

C# 将服务安装为x64

C# 将服务安装为x64,c#,visual-studio-2010,exception,windows-installer,C#,Visual Studio 2010,Exception,Windows Installer,我使用Visual Studio 2010在64位系统上开发了一项服务。该服务只是访问辅助库中的Start和Stop方法的框架。该库访问64位COM对象,并且必须构建为x64。COM对象是作为x64单独构建并在64位环境中测试的dll。我有一个安装程序,它设置项目并通过自定义操作安装服务 我使用绕过服务的测试应用程序调试代码,因此我可以确认服务正在访问的库是否正常工作 我遇到的问题是安装时出现了一个BadImageFormatException。我正在使用目标平台为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一样好。我非常感谢您的建议。

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

我尝试了Alex和Jacob Seleznev的解决方案,它们都很有效。我发现雅各布的第二个答案,格雷格·桑森,提供了最好的解决方案。为了帮助其他人,我将他的答案复制如下:

如果安装程序正在安装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 65781335


Exact System.BadImageFormatException当从VS2010安装程序项目安装程序时感谢您指出这一点,Jacob。我确实选择了正确的先决条件,但我正在研究Greg Sansom的第二个答案,看看它是否能解决我的问题。祝你好运。把答案贴出来,随便哪个有效。@Jacob,就是这样。如果你想用那篇文章的链接来回答这个问题,我会感谢你。我利用了格雷格给出的步骤。谢谢。默认情况下,
InstallUtil
的32位版本可以在
C:\Windows\Microsoft.NET\Framework\v4.0.30319
中找到,而64位版本可以在
C:\Windows\Microsoft.NET\Framework64\v4.0.30319
中找到。