2010-11-08 171 views
1

试图在W7 64位上运行,在Visual C#2008 Express上使用.Net 3.5,我尝试在Framework和Framework64文件夹中运行installutil.exe,两者都抛出相同的错误。 3.5文件夹没有installutil.exe和4.0两个文件夹都不起作用。InstallUtil引发错误信息

在IDE中,没有发布版本,但发布,他们是一样的吗?

我按照教程从这篇文章: http://www.switchonthecode.com/tutorials/creating-a-simple-windows-service-in-csharp

出了什么问题?

D:\install>C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe setup.e 
xe 
Microsoft (R) .NET Framework Installation utility Version 2.0.50727.4927 
Copyright (c) Microsoft Corporation. All rights reserved. 

Exception occurred while initializing the installation: 
System.BadImageFormatException: Could not load file or assembly 'file:///D:\inst 
all\setup.exe' or one of its dependencies. The module was expected to contain an 
assembly manifest.. 
+0

有没有人使用这个工作? – user1040975 2017-07-21 16:51:44

回答

4

System.BadIMageFormatException当尝试加载一个64位的组件或本地DLL在一个32位的上下文或反之亦然通常发生。

如果您在64位版本的Windows上运行,还有一个目录c:\windows\Microsoft.Net\Framework64\。尝试在其中一个子目录中找到的installutil。

另一个可能的问题是您正在运行InstallUtil而不是错误的程序集(.exe或.dll)。你正在运行setup.exe。在你所指的教程中没有显式的安装程序。 InstallUtil针对MyWindowsService.exe运行。在本教程中,您将创建一个使用System.Configuration.Install命名空间的程序。 InstallUtil使用该名称空间中的属性[RunInstaller(true)]来查找程序集中的“安装说明”,因此不需要单独的安装程序(setup.exe)。

你有没有试过按照教程的第一个字母,然后用自己的代码扩展它?

+0

我已经试过了。 – Proyb2 2010-11-08 07:02:39

+0

您是否也回顾我的第二个建议?你试图在错误的对象上运行installutil? – 2010-11-08 07:05:46

+0

我是C#的新手,那么这个建议是什么意思呢?那么我怎样才能使用setup.exe以外的其他功能呢? – Proyb2 2010-11-08 07:13:31

2

在.NET 4中构建Windows服务并尝试使用.NET v2目录中的installutil.exe进行安装时,您会遇到同样的问题。您必须使用.NET v4目录下的installutil.exe(Windows/Microsoft .NET Framework/v4.0.30319/installutil.exe)