61

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?

4
  • 1
    If you get startup errors you can enable extra startup options to output the actual reason. Have a look at my blog post about it. pkula.blogspot.co.uk/2017/11/… Commented Nov 15, 2017 at 10:58
  • Possible dublicate: stackoverflow.com/questions/43493259/… Commented Aug 24, 2018 at 9:22
  • 1
    @PiotrKula OMG, thanks :) I had issue with create database at startup Commented Jun 5, 2019 at 6:25
  • Glad it helped. They could just do that I the template commented out or so Commented Jun 16, 2019 at 16:36

7 Answers 7

121

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.

Sign up to request clarification or add additional context in comments.

7 Comments

For reference, go to your Azure Dashboard -> All Resources -> Your App Service -> Application Settings in the left hand sidebar -> scroll down to Application settings which is a key:value pair of settings, input the above. Restart your web app and you should have a nice error message displayed. Thanks Suneet, hours of debugging were fixed by this!
Works, but would you want to use this/leave this enabled on a production site?
@Andrew no definitely do not. Disable this after you resolve the issue. Don't wanna be leaking out troubleshooting details in prod when not needed.
This worked! Only that it seems the location of the setting was different for me. It was under the app service -> Configuration (in the settings section on the left navigation). Is there a way to have such information logged so I can see it later but not visible in the production site to users?
Somebody please give these instructions for non azure applications please :/
|
7

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” />

3 Comments

look something like what?
once you enable it in the web.config, how do you tell IIS to log there? It doesn't log any errors at all even after changing the web.config and rebooting the server! Is there another special, hidden, secret setting somewhere? I hate IIS for lack of the complete steps necessary to do even the simplest of things (like logging errors).
Adding to @NoloMokgosi answer above. Don't forget to give proper permissions to newly created log folders.@MC900 have you given proper permissions?
6

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

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

Comments

3

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.

Comments

3

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.

1 Comment

i'm getting this rows wih the command: C:\inetpub\2>dotnet DiscountPoolBackbone.dll info: Microsoft.Hosting.Lifetime[0] Now listening on: localhost:5000 info: Microsoft.Hosting.Lifetime[0] Now listening on: localhost:5001 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Production info: Microsoft.Hosting.Lifetime[0] Content root path: C:\inetpub\2
2

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.

2 Comments

Please explain how you "set log folder on the Azure server".
@Andrew On FTP server create folder on below location "/site/wwwroot/logs" also configure in webconfig file like this "<aspNetCore requestTimeout="00:30:00" processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"> <environmentVariables /> </aspNetCore>"
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.