Skip to content

With UseWindowsService, exceptions during configuration aren't reported as service startup exceptions #50018

Description

@davidmatson

Describe the bug

Exceptions starting up the host aren't reported as Windows service startup failures.

To Reproduce

  1. Use the program below.
  2. 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:

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;

static class Program
{
    static void Main()
    {
        new HostBuilder()
            .ConfigureLogging(l => l.AddConsole())
            .ConfigureServices((s) =>
            {
                throw new InvalidOperationException("Configuring services failed for some reason.");
            })
            .UseWindowsService()
            .Build()
            .Run();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions