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

旧时模样 提交于 2020-06-29 04:15:18

问题


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:


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.



来源:https://stackoverflow.com/questions/62192900/exe-installation-throwing-error-the-module-was-expected-to-contain-an-assembly-m

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