I have been working on a site in .Net Core 2.0 for several months. I just upgraded to .Net Core 2.1 and now the Startup.Configure()
method is not being called.
I have the following code in my Program
class, which creates the IWebHost
:
private static IWebHost BuildWebHost(string[] args)
{
return WebHost
.CreateDefaultBuilder()
.ConfigureAppConfiguration(LoadAppConfiguration)
.UseStartup<Startup>()
.Build();
}
Until I upgraded the framework, this was working perfectly, instantiating Startup
and correctly calling the ConfigureServices
and Configure
methods.
Now, although Startup
is being instantiated, Configure
is no longer being called. (No exceptions are being thrown.)
I realise there is a lot of other code in my application start up. But the only thing that I have done is to update the .Net Core SDK from 2.0 to 2.1.
Perhaps someone has an idea what might have changed or what I can investigate?
It turns out that the startup sequence has changed since .Net Core 2.0. I have not found any documentation or discussion on GitHub to confirm this, but my own testing has been clear.
It used to be that Startup.Configure
got called by WebHostBuilder.Build()
. But this call is now deferred to WebHost.Run()
[or WebHost.Start()
if you are using that].
I managed to get around it by injecting IApplicationLifetime
and registering a callback to perform my database migration etc. For what it is worth, I think the startup sequence is quite convoluted now and it would be nice to have a few simpler hooks to run code at the necessary points.
Thanks to everyone that commented or offered suggestions.
For me the answer was to just restart visual studio.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With