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
With UseWindowsService, exceptions during configuration aren't reported as service startup exceptions #50018
Exceptions starting up the host aren't reported as Windows service startup failures.
To Reproduce
Use the program below.
Start the service.
Expected behavior
Net start reports the service failed to start, and the startup exception is logged in event viewer.
Actual behavior
Net start reports the service didn't respond to the control request in a timely fashion, and the startup exception is not logged in event viewer.
Additional context
Program.cs:
usingMicrosoft.Extensions.Hosting;usingMicrosoft.Extensions.Logging;usingSystem;staticclassProgram{staticvoidMain(){newHostBuilder().ConfigureLogging(l =>l.AddConsole()).ConfigureServices((s)=>{thrownewInvalidOperationException("Configuring services failed for some reason.");}).UseWindowsService().Build().Run();}}
Seems like we should take a look at this. Hopefully there's a hook we can catch here. If it happens during process main we may be a little stuck since the exception is happening before any of the logging can be set up.
Just found this in a .NET core service I've written where there was a simple mistake in a connection string inside the appsettings.json file. It was throwing an exception, I was catching it and trying to log an error, but it never got logged and nothing useful in the event log either, so took me a while to debug.
the startup exception is not logged in event viewer.
This is trickier since we don't have any logging set up yet. I'm surprised that the exception isn't going anywhere, since the runtime is supposed to write startup exceptions to the Application Event Log.
Triage: We'll do a quick investigation after fixing dotnet/extensions#2836 and see if the event shows up somewhere now that we're properly exiting.
Activity
analogrelay commentedon Jan 8, 2020
Seems like we should take a look at this. Hopefully there's a hook we can catch here. If it happens during process main we may be a little stuck since the exception is happening before any of the logging can be set up.
simongymer commentedon Mar 3, 2020
Just found this in a .NET core service I've written where there was a simple mistake in a connection string inside the appsettings.json file. It was throwing an exception, I was catching it and trying to log an error, but it never got logged and nothing useful in the event log either, so took me a while to debug.
analogrelay commentedon Apr 24, 2020
This is probably due to dotnet/extensions#2836 rather than the exception itself.
This is trickier since we don't have any logging set up yet. I'm surprised that the exception isn't going anywhere, since the runtime is supposed to write startup exceptions to the Application Event Log.
Triage: We'll do a quick investigation after fixing dotnet/extensions#2836 and see if the event shows up somewhere now that we're properly exiting.
davidmatson commentedon Sep 25, 2025
/keep-alive
simongymer commentedon Sep 25, 2025
+1
rosebyte commentedon Jan 20, 2026
Duplicate of #50019?
cincuranet commentedon Jan 20, 2026
@rosebyte I think the root cause might be same/similar, but it is slightly different problem.