I have a problem with a shelved Topshelf service that doesn’t start when it’s supposed to: even though the shelf folder changes, and Topshelf notices this, the service is not started. No error messages (no log messages at all, actually) are shown, and I really don’t know where to start looking for the problem.
This is what I have:
-
I have verified in the logs that Topshelf notices a change in the folder
C:\Topshelf.Host\Services\MyService\. -
I have verified that the file names in the Topshelf shelf folder are
MyAssembly.dllandMyAssembly.config.MyAssemblyandMyServiceare the same, matching even on case. -
I have the following in my configuration file:
<configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> <section name="ShelfConfiguration" type="Topshelf.Shelving.ShelfConfiguration, TopShelf" /> </configSections> <ShelfConfiguration Bootstrapper="MyNamespace.MyBootstrapper, MyAssembly" /> ... -
I have the following classes in
MyAssembly.dll:namespace MyNamespace { public class MyBootstrapper : Bootstrapper<MyService> { public void InitializeHostedService(IServiceConfigurator<MyService> cfg) { cfg.HowToBuildService(name => new MyService()); cfg.WhenStarted(s => s.StartService()); cfg.WhenStopped(s => s.StopService()); } } public class MyService { public void StartService() { ... } public void StopService() { ... } } }
It turns out everything I included in the question was indeed correctly setup, but I had typos in other places of the config file that gave Topshelf trouble when loading my service. When I corrected those, everything worked as expected.
I’m closing the question, as the problem wasn’t really here.