In this article, we will continue to discuss Asp.net core error that you can find when deploying your Asp.net core application. We have few tutorial discussing about Asp.net core error in the past. Now, we will discuss other error in this tutorial.
Issue
I believe that you can find this error when deploying your Asp.net core application. Here is the error message:
“An error occurred while starting the application. .NET Framework <version number> | Microsoft.AspNetCore.Hosting version <version number> | Microsoft Windows <version number>”
You can see figure below:
Root of the Issue
If you see above error message, it means that there is an issue with your application, probably because these 3 factors below:
- You might not have the correct .NET Core version installed on the server.
- You might be missing DLL’s
- Something went wrong in your Program.cs or Startup.cs before any exception handling kicked in
You can’t find the answer on your Event Viewer
Based on your prior ASP.NET knowledge, you might immediately go to the Event Viewer if you’re running on Windows and behind IIS to see what occurred. You’ll see that the error has been removed. This is due to the fact that Event Logging must be explicitly set up, you must use the Microsoft.Extensions.Logging.EventLog package, and depending on the error, you might not even have a chance to catch it in time to log it to the Event Viewer.
Then, how to fix this issue?
If you are running behind IIS, we can log the request out to a file instead of the Event Viewer. To do that:
- Open your web.config
- Change stdoutLogEnabled=true
- 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.
- Unfortunately, the AspNetCoreModule doesn’t create the folder for you by default
- Run your request again, then open the \logs\stdout_*.log file
Reminder: Because it affects performance, you should disable this after you’ve finished troubleshooting.
So your web.config’s aspNetCore element should look something like this
<aspNetCore processPath=”.\YourProjectName.exe” stdoutLogEnabled=”true” stdoutLogFile=”.\logs\stdout” />
By doing this, all requests will be logged to this file, and when an exception occurs, it will show you the complete stack trace of what happened in the logsstdout_*.log file.
Hope this helps!
Conclusion
I hope the article above can help you to handle “An error occurred while starting the application“. There are still many errors that you can encounter when publishing the Asp.net core application. And we will certainly continue to provide interesting tutorials about Asp.net.
If you are looking for quality Asp.net hosting, you can directly visit our website at https://www.asphostportal.com. We always support the latest Asp.net version.
Andriy Kravets is writer and experience .NET developer and like .NET for regular development. He likes to build cross-platform libraries/software with .NET.