diff --git a/src/NSwag.Commands/HostApplication.cs b/src/NSwag.Commands/HostApplication.cs index 6b18983ff2..0f14f77991 100644 --- a/src/NSwag.Commands/HostApplication.cs +++ b/src/NSwag.Commands/HostApplication.cs @@ -140,7 +140,13 @@ void OnEntryPointExit(Exception exception) try { // Get the IServiceProvider from the host +#if NET6_0 + var assemblyName = assembly.GetName()?.FullName ?? string.Empty; + // We should set the application name to the startup assembly to avoid falling back to the entry assembly. + var services = ((IHost)factory(new[] { $"--{HostDefaults.ApplicationKey}={assemblyName}" })).Services; +#else var services = ((IHost)factory(Array.Empty())).Services; +#endif // Wait for the application to start so that we know it's fully configured. This is important because // we need the middleware pipeline to be configured before we access the ISwaggerProvider in @@ -176,4 +182,4 @@ public void Dispose() { } public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; } } -} \ No newline at end of file +}