Issue
After deploying a .NET Core app to an Azure AppService your site returns the following error:
HTTP Error 500.30 - ASP.NET Core app failed to start
Resolution
This error can come up for any numbers of reasons but generally it's because an unhandled exception has occurred in Startup.cs
or in Program.cs
(in .NET 6 Program.cs
is where most of the startup logic runs by default).
In order to troubleshoot this you'll need to step through each piece of the startup to determine what is causing the exception. In my case, I had added a config for development with an optional flag set to false
which stopped the pipeline when it didn't exist in production.
Program.cs
builder.Host.ConfigureAppConfiguration((ctx, config) =>
{
config.AddJsonFile("appsettings.json",
optional: false,
reloadOnChange: true)
.AddJsonFile($"appsettings.{ctx.HostingEnvironment.EnvironmentName}.json", optional: true);
});
If you don't have the logs available if you need a better message on Azure, you can go into the Azure portal and add an environment variable for ASPNETCORE_ENVIRONMENT
and set the value to Development
. Azure will then show you the detailed error information including the stack trace. Remember, don't forget to remove that environment variable when you're done or reset it to Production
.