为什么我无法安装我的服务(运行时比加载的运行时更新)?

发布于 2024-10-03 00:54:18 字数 740 浏览 8 评论 0原文

所以我用 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 中的。

有没有人有这个问题的经验?

So I built a service in C# and I am trying to use the following command to install it:

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

It fails. When I look at the installLog.txt, I get this:

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..

The same approach works fine for installing a different assembly. I feel like it might be because the one that fails was written for .NET 4.0, and the one that works is in 3.5.

Does anyone have any experience with this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

ゝ杯具 2024-10-10 00:54:18

如果您的应用程序是针对 .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

You are using the wrong installutil.exe If your application is built against .Net 4.0. Use the the installutil.exe in the 4.0 folder.

For x86:

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

For x64:

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

真心难拥有 2024-10-10 00:54:18

甚至没有人接近得到这个!

这是我必须做的:

  1. 右键单击 Visual Studio 中的服务项目,转到“属性”,
  2. 将“启动对象”设置为服务的名称(它已设置为值“(未设置)”)。
  3. 节省。
  4. 构建
  5. 尝试再次安装。
  6. 有用!耶!我们都可以回家了!

链接到代码项目文章,该文章有帮助:

Nobody even came close to getting this one!

Here's what I had to do:

  1. Right-click the service project in Visual Studio, go to "Properties"
  2. Set "Startup object" to the name of the service (it had been set to the value "(Not Set)").
  3. Save.
  4. Build
  5. Try to install again.
  6. It works! Yay! We can all go home!

Link to the code project article that helped:

等风来 2024-10-10 00:54:18

对于那些没有发现这可以解决问题的人,您需要查看 .vdproj 文件的启动条件并将 .NET Framework 更改为 4:http://www.alexjamesbrown.com/uncategorized/deploying-net-4-project-error-1001-system-badimageformatexception/< /a>

For those of you who don't find that this fixes their problem you need to look in the Launch conditions of the .vdproj file and change the .NET framework to 4: http://www.alexjamesbrown.com/uncategorized/deploying-net-4-project-error-1001-system-badimageformatexception/

坦然微笑 2024-10-10 00:54:18

对我来说,我只是右键单击我尝试安装的 exe,然后单击“取消阻止”

For me I just right right clicked on the exe I was trying to install and clicked "Unblock"

╭ゆ眷念 2024-10-10 00:54:18

如果您在 x64 机器上编译,请务必进入 Configuration Mgr 并将构建更改为 x64。当然,您需要检查以确保您使用的是正确版本的 InstallUtil.exe。祝你好运。

If you compile on x64 machine, be sure to go into Configuration Mgr and change the build to x64. Of course you'd want to check to make sure you're using the right version of InstallUtil.exe. g'luck.

知足的幸福 2024-10-10 00:54:18

遇到同样的问题,上面的内容对 Windows Server 2019 尝试运行兼容性测试没有任何帮助

,之后注册突然起作用:
输入图片此处描述

Having same issue, nothing from above was helping on windows server 2019

tried to run compatibility test, after that the registration suddenly worked:
enter image description here

三五鸿雁 2024-10-10 00:54:18

我相信您在问题中提供了答案:

“该程序集是由比当前加载的运行时更新的运行时构建的,无法加载。”

因此,您可能已经使用较新的函数(位于较新的框架中)编译了运行时,但您正在注册的计算机运行的版本较低。

例如。针对 .NET 3.5 进行编译,但随后在 .NET 2.0 上安装该服务是没有意义的。

由于您能够在目标计算机上安装服务,我猜您已经是管理员了。因此,只需升级该服务机器上的 .NET 框架即可。

I believe you provide the answer in your question:

"This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.."

So you might have compiled the runtime with newer functions (which are in newer Frameworks) but the computer you are registrating it on is running a lower version.

Eg. compile for .NET 3.5 but install the service afterwards on a .NET 2.0 wouldnt make sense.

Since you are able to install services on the destination machine, I guess you already are admin. So just upgrade the .NET framework on that service-machine.

绿光 2024-10-10 00:54:18

您是否尝试过在包含 Windows 服务的目录中的命令提示符窗口中简单地键入 MyService.exe /install ?这在过去对我有用。您还可以使用 MyService.exe /uninstall 卸载 Windows 服务。

Have you tried simply typing MyService.exe /install in a Command Prompt window in the directory containing your Windows service? That has worked for me in the past. You can also uninstall a Windows service by using MyService.exe /uninstall.

娇女薄笑 2024-10-10 00:54:18

我也有同样的问题。最初,我的项目位于 D:\ 项目调试文件夹内的一条很长的路径中。
我将 .exe 服务文件移动到另一个路径较短的位置并以“C:\”开头时,问题得到解决。

我还使用这个批处理文件来安装我的服务

@ECHO OFF

REM Directory for .NET 4. Check for other version directories.
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX2%

echo Installing MyService...
echo ---------------------------------------------------
InstallUtil /i C:\ServiceFolder\MyService.exe
echo ---------------------------------------------------
echo Done.
pause

I had the same problem. Initially my project was in a very long path on D:\ inside the debug folder of my project.
The problem was solved when I moved the .exe service file to another location with a shorter path and started with "C:\".

I also use this batch file to install the my services

@ECHO OFF

REM Directory for .NET 4. Check for other version directories.
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX2%

echo Installing MyService...
echo ---------------------------------------------------
InstallUtil /i C:\ServiceFolder\MyService.exe
echo ---------------------------------------------------
echo Done.
pause
难以启齿的温柔 2024-10-10 00:54:18

如果您尝试了上述所有操作,但仍然看到相同的错误,请仔细检查您是否有 32 位应用程序或任何 32 位 DLL,并且您的服务器是否是 64 位服务器。

If you tried all the above and still see the same error, double check if you have a 32-bit application or any 32-bit DLLs and your server is a 64-bit server.

表情可笑 2024-10-10 00:54:18

在这上面浪费了一个小时,我所要做的就是为服务路径添加引号。

步骤 1) cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

将 .exe 路径的目录添加到引号中,如图所示

步骤 2) InstallUtil.exe "E:\MyNewService\MyNewService\bin\Debug\MyNewService。 exe”

参考:https:// www.codeproject.com/Answers/5143174/Installing-windows-service-error-installutil-exe-i#answer5

Wasted an hour on this,all I had to do was add quotes for the service path.

Step 1) cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

add the directory of the .exe path in quotes as shown

step 2) InstallUtil.exe "E:\MyNewService\MyNewService\bin\Debug\MyNewService.exe"

ref: https://www.codeproject.com/Answers/5143174/Installing-windows-service-error-installutil-exe-i#answer5

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文