How to troubleshoot: “An error occurred while starting the application” in ASP.NET Core on IIS

The Problem

If you’ve ever seen this message when hitting your ASP.NET Core app:

“An error occurred while starting the application.  .NET Framework <version number> | Microsoft.AspNetCore.Hosting version <version number> | Microsoft Windows <version number>”

It looks a little something like this:



What Happened?

It basically means something really bad happened with your app.  Some things that might have gone wrong:

  1. You might not have the correct .NET Core version installed on the server.
  2. You might be missing DLL’s
  3. Something went wrong in your Program.cs or Startup.cs before any exception handling kicked in


Event Viewer (probably) won’t show you anything

If you’re running on Windows and behind IIS, you might immediately go to the Event Viewer to see what happened based on your previous ASP.NET knowledge.  You’ll notice that the error is not there.  This is because Event Logging must be wired up explicitly and you’ll need to use the Microsoft.Extensions.Logging.EventLog package, and depending on the error, you might not have a chance to even catch it to log to the Event Viewer.


How to figure what happened (if running on IIS)

Instead of the Event Viewer, if you’re running behind IIS, we can log the request out to a file.  To do that:

  1. Open your web.config
  2. Change stdoutLogEnabled=true
  3. Create a logs folder
    1. Unfortunately, the AspNetCoreModule doesn’t create the folder for you by default
      1. 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.
    2. The “stdout” part of  the value “.\logs\stdout” actually references the filename not the folder.  Which is a bit confusing.
  4. 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” />


Doing this will log all the requests out to this file and when the exception occurs, it will give you the full stack trace of what happened in the \logs\stdout_*.log file






Hope this helps.  This happened to me a friend of mine.  A friend.  Yep.  Definitely not me.  My apps would never bomb.

33 thoughts on “How to troubleshoot: “An error occurred while starting the application” in ASP.NET Core on IIS

  1. If you’re hosting this on a server that you can access, another way to find startup errors is by running `dotnet YourAspNetCoreProject.dll` from a command prompt.

    Liked by 1 person

  2. I cannot being to express how much of a life saver your article was. Something as simple as outputting the log saved me as our production system was down and there’s nothing in any log that is descriptive of what is happening, but the kestrel output was perfect. Thanks again!

    Liked by 1 person

    • Sorry for the late response Tayo… I’m not really sure to be honest as I’m not familiar with AppHarbor. If they let you throttle up the logging some how that seems like the best bet. If you found a solution it’d be awesome to share it so the next person may benefit!


  3. Hey Scott,
    It still didn’t help to solve any issue. I have created the logs folder, however it doesn’t create any file inside the folder. On other hand the same problem still is there.


    • Hi Farid – Just checking, you changed the web.config file too right? The other thing to check would be permissions that the user the app pool is running under has permissions to create files.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s