You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Service is being created with executable path pointing to DLL instead of EXE #8
usingSystem.ComponentModel;usingSystem.Configuration.Install;usingSystem.ServiceProcess;namespaceTestServiceInstall{[RunInstaller(true)]publicclassTestServiceInstaller:Installer{publicTestServiceInstaller(){ServiceProcessInstallerprocessInstaller=newServiceProcessInstaller();ServiceInstallerserviceInstaller=newServiceInstaller();// set the privilegesprocessInstaller.Account=ServiceAccount.LocalSystem;serviceInstaller.DisplayName=GlobalVar.SERVICE_NAME;serviceInstaller.StartType=ServiceStartMode.Automatic;serviceInstaller.DelayedAutoStart=true;serviceInstaller.ServicesDependedOn=newstring[]{"Tcpip"};// must be the same as what was set in Program's constructorserviceInstaller.ServiceName=GlobalVar.SERVICE_NAME;// installer code herethis.AfterInstall+=newInstallEventHandler(ServiceInstaller_AfterInstall);this.Installers.Add(processInstaller);this.Installers.Add(serviceInstaller);}voidServiceInstaller_AfterInstall(objectsender,InstallEventArgse){ServiceControllersc=newServiceController(GlobalVar.SERVICE_NAME);sc.Start();}}}
We tried to migrate to .NET 6.0 and use this library to install the service in a same way we used to, but what happens is service binary path changed from EXE file to DLL file and we can't figure out how to point it to the EXE file.
We've tried changing Assembly.GetExecutingAssembly().Location to Environment.ProcessPath but it gives us the following error:
System.BadImageFormatException: Bad IL format. The format of the file '%EXE path here%' is invalid..
So the question is how can we use this library to install a windows service pointing to EXE file instead of DLL?
It didn't show me the stack trace besides my own code:
PS Y:\> .\bin\Release\net6.0-windows10.0.22000.0\TestService.exe --install
ERROR 2021-12-07 14:41:15,428 - Exception running TestService: System.InvalidOperationException: Exception occurred while initializing the installation:
System.BadImageFormatException: Bad IL format. The format of the file 'Y:\bin\Release\net6.0-windows10.0.22000.0\TestService.exe' is invalid..
at System.Configuration.Install.ManagedInstallerClass.InstallHelper(String[] args)
at TestService.Program.Main(String[] args) in Y:\Program.cs:line 168
And with Assembly.GetExecutingAssembly().Location there're no errors, service is being created, but binPath points to TestService.dll instead of TestService.exe and it doesn't start.
The following fixes it and service starts just fine:
Hm... I'm not sure that the bug is related to this package because the package does not use SCM. How do you install the service? Do you use ServiceProcessInstaller from System.ServiceProcess.dll?
Activity
flamencist commentedon Dec 9, 2021
Please provide a full exception stack trace for the first variant
I think you have the issue due to different runtimes. In the library we use Assembly.LoadFrom(Assembly.GetExecutingAssembly().Location )
Core.System.Configuration.Install/System.Configuration.Install/System.Configuration.Install/ManagedInstallerClass.cs
Line 50 in 11ba491
xeron commentedon Dec 9, 2021
It didn't show me the stack trace besides my own code:
And with
Assembly.GetExecutingAssembly().Locationthere're no errors, service is being created, butbinPathpoints toTestService.dllinstead ofTestService.exeand it doesn't start.The following fixes it and service starts just fine:
flamencist commentedon Dec 21, 2021
Hm... I'm not sure that the bug is related to this package because the package does not use SCM. How do you install the service? Do you use
ServiceProcessInstallerfrom System.ServiceProcess.dll?