Skip to content

WebHostBuilderExtensions Configure can result in HostingStartupAssemblies being run twice #31382

Closed
@k-s-s

Description

@k-s-s

Describe the bug

Background

I am using IHostingStartup within my package library as it is used by external users to create the web host, targets NET 4.6 and NET Core 3.1. I set the builder setting HostingStartupAssembliesKey to package library assembly FullName
I have added a feature to add use an instanced startup class instead of using the normal UseStartup. It is a custom interface, not Microsoft.AspNetCore.Hosting.IStartup
The intention is for testing, to make an easier way of testing different services, rather than separate startup classes.

Bug

  1. When using the Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.Configure method (I add the method of the instanced startup), the extension method sets WebHostBuilder setting ApplicationKey to startup assembly. This was not correct as it was setting to the package library, using assembly Name
    public static IWebHostBuilder Configure(this IWebHostBuilder hostBuilder, Action<WebHostBuilderContext, IApplicationBuilder> configureApp)
  2. When I do host.Build(), the method:
    private IServiceCollection BuildCommonServices(out AggregationException hostingStartupErrors)
    create WebHostOptions, which registers 2x hosting startup assemblies because of Name and FullName

To Reproduce

  1. Use IHostingStartup, using assembly FullName
  2. Use WebHostBuilder.Configure
  3. Run WebHost.Build()

Exceptions (if any)

I found the issue that Swashbuckle raised an exception that a document was already registered.

Further technical details

  • NET 4.6.1, NET Core 3.1

Metadata

Metadata

Assignees

Labels

area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions