Exe installation throwing error The module was expected to contain an assembly manifest .Net Core

Viewed 2963

I have implemented windows service using .Net Core worker service. When installing service from command prompt, getting error

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe D:\LC\WindowService\L3WorkerService.exe
Microsoft (R) .NET Framework Installation utility Version 4.8.3752.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 
'file:///D:\LC\WindowService\L3WorkerService.exe' or one of its dependencies. 
The module was expected to contain an assembly manifest..

I have tried with these two path

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe D:\LC\WindowService\L3WorkerService.exe
C:\Windows\Microsoft.NET\Framework\v4.0.30319>InstallUtil.exe D:\LC\WindowService\L3WorkerService.exe

This is my project information

  • Platform target - x86
  • Output type - WindowsApplication
  • Target Framework - .NET Core 3.1

How can I fix this issue?

1 Answers

To install service need to follow below steps

open cmd as admin and switch to output/publish dir of project. Then type

sc create TestService BinPath=D:\LC\WindowService/TestService.exe

You will get message [SC] CreateService SUCCESS. Other commands also available including start service

sc start TestService
sc stop TestService
sc delete TestService

Note: In .Net Core services avoid using InstallUtil.exe.

Related