c# - 为什么我不能安装我的服务(运行时比加载的运行时更新)?

标签 c# .net windows-services failed-installation

所以我在 C# 中构建了一个服务,并尝试使用以下命令来安装它:

C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\installutil.exe MyService.exe >> installLog.txt

它失败了。当我查看 installLog.txt 时,我得到了这个:

Microsoft (R) .NET Framework Installation utility Version 2.0.50727.3053
Copyright (c) Microsoft Corporation.  All rights reserved.

Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\MyService.exe' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded..

相同的方法适用于安装不同的程序集。我觉得这可能是因为失败的是为 .NET 4.0 编写的,而有效的是 3.5。

有人遇到过这个问题吗?

最佳答案

如果您的应用程序是针对 .Net 4.0 构建的,您使用的是错误的 installutil.exe。使用4.0文件夹下的installutil.exe。

对于 x86:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe

对于 x64:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe

关于c# - 为什么我不能安装我的服务(运行时比加载的运行时更新)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4216606/

相关文章:

.NET TAPI 接口(interface)

c# - Windows Service增加CPU消耗

c# - 如何强制对泛型进行 downcast

c# - 可以在 .Net 4.0 中使用 Tuple 的实际示例?

c# - 如何调整 Windows Server 服务总线中 BrokeredMessage 的最大消息大小?

c# - 从也使用其中一些包的项目中引用使用 NuGet 包的程序集

c# - 在两个类实例之间动态复制某些属性

c# - F#的静态绑定(bind)约束是如何实现的?

来自 dll 的 .NET Windows 服务

C# TCP 服务器停止接收客户端消息,在服务重新启动时恢复