-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebHostBuilderExtensions Configure can result in HostingStartupAssemblies being run twice #31382
Comments
@k-s-s do you have a sample application? |
Trying to interpret what you put in the issue, this is what I came up with so far. I know I'm missing something 😄 . using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
[assembly: HostingStartup(typeof(WebApplication50.HostingStartup))]
namespace WebApplication50
{
public class HostingStartup : IHostingStartup
{
public void Configure(IWebHostBuilder builder)
{
}
}
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseSetting(WebHostDefaults.HostingStartupAssembliesKey, typeof(Program).Assembly.FullName)
.Configure(new Startup().Configure);
});
}
} |
Hi David That looks about right, if you put a breakpoint on the HostingStartup.Configure, I think it should call twice. In the HostingStartup.Configure method, to check, register singleton, that links to a static variable and will throw exception if already set. I will make a sample this weekend. |
No need, I can reproduce the problem and will have a fix out ASAP. |
@Tratcher should we back port this? |
Why? This one report doesn't seem to justify that. |
It's not about the number of reports, it's about the potential impact, and re-reading this issue again I don't think its common to set a different assembly name like this. |
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
public static IWebHostBuilder Configure(this IWebHostBuilder hostBuilder, Action<WebHostBuilderContext, IApplicationBuilder> configureApp)
private IServiceCollection BuildCommonServices(out AggregationException hostingStartupErrors)
create WebHostOptions, which registers 2x hosting startup assemblies because of Name and FullName
To Reproduce
Exceptions (if any)
I found the issue that Swashbuckle raised an exception that a document was already registered.
Further technical details
The text was updated successfully, but these errors were encountered: