Search code examples
c#.netwindows-servicesinstallutil

Why can't InstallUtil.exe find the manifest file?


I am trying to create a Windows service following this tutorial:

https://www.c-sharpcorner.com/UploadFile/8a67c0/create-and-install-windows-service-step-by-step-in-C-Sharp/

I am using batch code to install the service:

@echo off
cd C:\Users\User\Desktop\C#\TestService\bin\Debug
set DOTNET=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727
set PATH=%PATH%;%DOTNET%
installutil.exe /i TestService.exe
net start TestService
pause
net stop TestService
installutil.exe /u TestService.exe

When I run this file, I get the following error:

Exception occurred while initializing the installation: System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\User\Desktop\C#\TestService\bin\Debug\TestService.exe' or one of its dependencies. The module was expected to contain an assembly manifest.. The service name is invalid.

It says the module was expected to contain a manifest, but there is a manifest file in the directory. I've tried rebuilding but it doesn't change.

Any help would be greatly appreciated.


Solution

  • I changed the DOTNET path to %SystemRoot%\Microsoft.NET\Framework64\v4.0.30319 and made sure to run as administrator every time. This seemed to do the trick.