[Solved] HTTP Error 500.30 – ASP.NET Core app failed to start 



HTTP Error 500.30 – ASP.NET Core app failed to start


HTTP Error 500.30 – ASP.NET Core app failed to start, this error is obvious while hosting your Web API or Blazor, Web application developed in ASP.NET CORE, even in .Net 5. Azure app service responses suggest what might have caused this error - could it be app service stopped or throw an exception is the project is trying to host, usually on the configuration appsettings.json or startup.cs 

This error is not a big deal to leave unattended. Azure App service hosting is much faster than earlier. To host Web API or Web Application to App Service, the app service must be active and run.  

Key scenarios

What is HTTP Error 500.30 here?

HTTP Error 500.30 – ANCM In-Process Start Failure” is moreover a generic error. ... To add to this the error "500.30 In-Process Startup Failure", you may occur The worker process fails. The app doesn't start. The ASP.NET Core Module attempts to start the. NET Core CLR is in-process, but it fails to start.  
If you are a new Azure App Service  more info

 Azure App Service is a fully managed web hosting service for building web applications, services, and RESTful APIs. The service offers a range of plans to meet the needs of any application, from small websites to globally scaled web applications.
 

In this article, we will cover the problem description, root cause of the issue, and finally the solution.

A short description about my project work, I had Visual Studio Subscription for Azure account and using that created an Azure App Service to host my Web API developed.  The Web API is developed in ASP.NET Core (.NET 5).

Step 1: What is the Error?

Now the story changed like this, I have hosted my Web API earlier, and was working successfully. Later I continue to implement the logic to capture the exceptions in a log file to wwwroot folder in Web API Project Solution.

I now try to re-host the Web API to Azure App service - boom, the error appeared as below captured image.



HTTP Error 500.30 – ASP.NET Core app failed to start


By reading the suggested error from the Azure service would give us a piece of generic information. To spot the specific reason it is required to look at the exception log created by the app service.

Now, where do I find the error captured by Azure?

Login to your Azure Portal.

Please note that in this article we are trying to host web API to Azure App Service. So it is required to find the logs created by azure under App Service.


Step 2: What caused the Error?

At the end of step 1 directs you to log in to the Azure portal.  Go to Home > Resources > your App Service > Click on Diagnosis and solve problems, filter the error and find the exception message captured by App service. 

Here the exception message is captured not by our Web API application but the Azure App Service

Now let's take a look at the image below with numbers marked.


Azure App service exception




Application '/LM/W3SVC/2138455566/ROOT' physical root 'D:\home\site\wwwroot\' hit unexpected managed exception,exception code = '0xe0434352'. First 30KB characters of captured stdout and stderr logs: crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]  Application startup exception System.ArgumentNullException: Value cannot be null. (Parameter 'path1') at System.IO.Path.Combine(String path1, String path2).

The arrow points out number 6  the line number in which the error is captured and the exception is thrown.

What does that error say?

At the very first line of the error description in #6 points to \wwwroot, and further next line System.ArgumentNullException: Value cannot be null. (Parameter 'path1) 

The issue is very clear, in the startup.cs line number 122, you are trying to pass an argument that does not exist in Azure App Service.

Now let's go back to Visual Studio Solution Web API Project. 

Step 3: How do I solve the Error?

Open Visual Studio Project Solution Explorer, click on Startup.cs file, and locate to Configure method, and line number #122.

What does that line trying to do?

The line is trying to create a text log file under wwwroot folder "logs" of Azure App Service, the folder path would be wwwroot\logs\ but the Azure does not have the folder and the parameter  wenvironment.WebRootPath the value will always be null.

This is the reason, Azure host has failed to start.

Add log file to wwwroot


How do I rectify the error?

Add null checking to environment WebRootPath if empty create a directory under wwwroot folder and then add the log error to it.


Solved http error 500.30 – asp.net core app failed to start


Startup.cs

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                //app.UseExceptionHandler("/error-development");
            }
            else
            {
                app.UseHsts();
                //app.UseExceptionHandler("/error-staging");
            }
            // log errors 
            if (string.IsNullOrWhiteSpace(env.WebRootPath))
            {
                env.WebRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot");
            }
            // Create log folder if not exists
            if (!Directory.Exists(Path.Combine(env.WebRootPath, "logs"))) Directory.CreateDirectory(Path.Combine(env.WebRootPath, "logs"));

            loggerFactory.AddFile($"{Path.Combine(env.WebRootPath, "logs")}/log.txt");  
}


Hosting Tips! When hosting Web API or Web Application to Azure App Service, In Publish profile, Edit to tick "Remove additional files at destination".

Checking "Remove additional files at destination" will remove the existing files at Azure App Services files and replace them with the latest version of files every time publish from Visual Studio.

How do I do that?

In the Publish profile, click on "Edit" under File Publish Options check the box "Remove additional files at the destination".


Edit Publish Profile



Remove additional files at destination


Click on Save and now click on Publish button to host successfully.

That's it to solve the problem.


Summary

This article explains the solution for HTTP Error 500.30 - ASP.NET Core app failed to start

This error is prompted when we try to host Web API (.NET 5) from Visual Studio. Then we traced the exception captured by the Azure App Service in Diagnosis and solve problems and found that our Web API was trying to create a log file under this folder wwwroot\logs path that doe not exist in Azure App Service.

Then we added environment.WebRootPath null checks and then if the folder does not exist create a folder and then combine folder path log file to store.

We also learned a tip, In Publish profile edit to enable "Remove additional files at the destination" to help remove all existing files from the server every time publish from Visual Studio.

The key point is to ensure Azure App Service is up and running before hitting the Publish button from Visual Studio.