为什么我无法安装我的服务(运行时比加载的运行时更新)?
所以我用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
如果您的应用程序是针对 .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
甚至没有人接近得到这个!
这是我必须做的:
链接到代码项目文章,该文章有帮助:
Nobody even came close to getting this one!
Here's what I had to do:
Link to the code project article that helped:
对于那些没有发现这可以解决问题的人,您需要查看 .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/
对我来说,我只是右键单击我尝试安装的 exe,然后单击“取消阻止”
For me I just right right clicked on the exe I was trying to install and clicked "Unblock"
如果您在 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.
遇到同样的问题,上面的内容对 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:
我相信您在问题中提供了答案:
“该程序集是由比当前加载的运行时更新的运行时构建的,无法加载。”
因此,您可能已经使用较新的函数(位于较新的框架中)编译了运行时,但您正在注册的计算机运行的版本较低。
例如。针对 .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.
您是否尝试过在包含 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 usingMyService.exe /uninstall
.我也有同样的问题。最初,我的项目位于 D:\ 项目调试文件夹内的一条很长的路径中。
当我将 .exe 服务文件移动到另一个路径较短的位置并以“C:\”开头时,问题得到解决。
我还使用这个批处理文件来安装我的服务
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
如果您尝试了上述所有操作,但仍然看到相同的错误,请仔细检查您是否有 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.
在这上面浪费了一个小时,我所要做的就是为服务路径添加引号。
步骤 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