Azure WebApp Asp.NET Core 2 error: An error occurred while starting the application

C#asp.netasp.net MvcAzureasp.net Core

C# Problem Overview


I have upgraded asp.net core 1.1 to an asp.net core 2. It runs fine on the local server, but when I try to deploy it to an Azure hosted web app, I received the error:

> An error occurred while starting the application. .NET Core > > 4.6.00001.0 X86 v4.0.0.0 | Microsoft.AspNetCore.Hosting version 2.0.0-rtm-26452 | Microsoft Windows 6.2.9200

enter image description here

Any ideas?

C# Solutions


Solution 1 - C#

Please add ASPNETCORE_DETAILEDERRORS = true in app settings of your app, restart it and see the detailed error next time you load the url. That will help you fix it.

For example, error in my case was that I didn't have the managed identity of my API App configured to access the Key Vault to get the storage account and Cosmos DB keys. I used startup to inject the configured storage and cosmos db objects hence it was failing the moment I was starting my app.

When you've fixed the startup issue, don't forget to remove this setting as leaving it on could expose information about how the application works to visitors in the event of another error.

Solution 2 - C#

Got my tips from https://scottsauber.com/2017/04/10/how-to-troubleshoot-an-error-occurred-while-starting-the-application-in-asp-net-core-on-iis/

  1. Open your web.config
  2. Change stdoutLogEnabled=true
  3. Create a logs folder Unfortunately, the AspNetCoreModule doesn’t create the folder for you by default If you forget to create the logs folder, an error will be logged to the Event Viewer that says: Warning: Could not create stdoutLogFile \?\YourPath\logs\stdout_timestamp.log, ErrorCode = -2147024893. The “stdout” part of the value “.\logs\stdout” actually references the filename not the folder. Which is a bit confusing. Run your request again, then open the \logs\stdout_*.log file

Note – you will want to turn this off after you’re done troubleshooting, as it is a performance hit.

So your web.config’s aspNetCore element should look something like this

<aspNetCore processPath=”.\YourProjectName.exe” stdoutLogEnabled=”true” stdoutLogFile=”.\logs\stdout” />

Solution 3 - C#

Enable DetailedErrorsKey in the Program.cs so you can figure it out what's happening.

WebHost.CreateDefaultBuilder(args)
    .UseSetting(WebHostDefaults.DetailedErrorsKey, "true")

Solution 4 - C#

You can obtain more details by enabling ASPNETCORE_DETAILEDERRORS = true:

go to your Azure Dashboard -> Your App Service

In your application Settings (in the left hand sidebar) -> scroll down to configuration which is a key:value pair of settings, input the above. Restart your web app.

Solution 5 - C#

Try executing the application by firing the command

> dotnet myapplicationname.dll

This shall throw the startup errors and may help you narrow down the error.

Solution 6 - C#

I managed to solve the problem myself and I hope this solution might help someone.

First, I have set log folder on the Azure server and find issue with more details. I forgot some database changes in SQL.Update database changes and run it's working fine now.

Solution 7 - C#

I was able to discover my exceptions for this error by starting the app from it's published executable.

To try this locally, you can right click on the web project, click publish, and then publish it to a folder. There should be an executable in the folder of the same name as the project. Run that and it should show exceptions in the console.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionArvind SisaraView Question on Stackoverflow
Solution 1 - C#Suneet NangiaView Answer on Stackoverflow
Solution 2 - C#NoloMokgosiView Answer on Stackoverflow
Solution 3 - C#Masoud DarvishianView Answer on Stackoverflow
Solution 4 - C#MelchiaView Answer on Stackoverflow
Solution 5 - C#Sunil JohnsonView Answer on Stackoverflow
Solution 6 - C#Arvind SisaraView Answer on Stackoverflow
Solution 7 - C#farlee2121View Answer on Stackoverflow