From 63ee0c3ecd5c388e5bdb37f2f3b7ea92bc82b2a8 Mon Sep 17 00:00:00 2001 From: desjoerd Date: Sat, 3 Feb 2024 22:20:09 +0100 Subject: [PATCH] Only exclude explicit registrations of IHostedService This fixes issues when a registered class or interface inherits from IHostedService because they where removed even when it would not run as an IHostedService. --- src/NSwag.Commands/HostApplication.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/NSwag.Commands/HostApplication.cs b/src/NSwag.Commands/HostApplication.cs index d5e816d9d..0f17e8755 100644 --- a/src/NSwag.Commands/HostApplication.cs +++ b/src/NSwag.Commands/HostApplication.cs @@ -112,8 +112,9 @@ void ConfigureHostBuilder(object hostBuilder) // exclude all implementations of IHostedService // except Microsoft.AspNetCore.Hosting.GenericWebHostService because that one will build/configure // the WebApplication/Middleware pipeline in the case of the GenericWebHostBuilder. - if (typeof(IHostedService).IsAssignableFrom(services[i].ServiceType) - && services[i].ImplementationType is not { FullName: "Microsoft.AspNetCore.Hosting.GenericWebHostService" }) + var registration = services[i]; + if (registration.ServiceType == typeof(IHostedService) + && registration.ImplementationType is not { FullName: "Microsoft.AspNetCore.Hosting.GenericWebHostService" }) { services.RemoveAt(i); }