Why can't I install my service (runtime newer than loaded runtime)?

落花浮王杯 提交于 2019-11-28 17:33:21
Darryl Braaten

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.

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

SuperNES

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:

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/

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.

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

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.

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!