Hi Matt,
That was super helpful, even a year after you posted it. Thank you!
For me, this problem was very difficult to find since the effect did not immediately follow the cause. That is, the 503 error would manifest long after the call to the WebApplication.CreateBuilder method. I’ve spent months looking for the cause, and trying to find workarounds to seemingly random 503 errors.
I think the page “Configuration in ASP.NET Core” https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-8.0 should have a big warning like
NOTE: While we mention WebApplication.CreateBuilder(args) many times on this page, KIDS, DON’T TRY THIS AT HOME.
YOU SHOULD ONLY CALL WebApplication.CreateBuilder ONCE. The reason is explained in the IIS Support blog post here: https://techcommunity.microsoft.com/blog/iis-support-blog/asp-net-core-503-server-has-been-shutdown/3830338
I’ll submit a documentation issue about that.
Thanks again.
Dan