Blog About Me Posts By Tags Subscribe Elastic Search My Sessions Terraform

Pavan Kumar Aryasomayajulu


An error occurred while starting the application. .NET Core | Microsoft.AspNetCore.Hosting version | Microsoft Windows

Hi, In this post, I would like to explain how we can handle the following error that we usually get when hosting Asp.Net core application using IIS.


** An error occurred while starting the application. .NET Core | Microsoft.AspNetCore.Hosting version | Microsoft Windows **


An error occurred while starting the application.

.NET Core X86 v4.1.1.0    |   Microsoft.AspNetCore.Hosting version 1.1.1    |    Microsoft Windows 6.2.9200    |   Need help?

I was getting above error after publishing my code to a remote server and hosting it using IIS.
I was actually clueless and tried to find out what was the actual error, this particular message looks generic and there might be something that is actually causing this issue.



I tried looking at EventLogs but still, I don’t see any error message logging over there.

How to log error message in Asp.Net Core

  1. Go to Projects Web.Config file and try to enable error by setting true to “stdoutLogEnabled” property
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout">
      <environmentVariables />
    </aspNetCore>


  1. Also in the config file, we see the location where errors are supposed to be written.
  2. So by default Asp.Net core doesn’t create these folders, In our case ** “logs\stdout”. So go and create a folder by name **“logs”
  3. Go to Visual studio proj and add a folder by name “logs” at the root level and add a sample.txt file(this can be an empty one.. Just because if the content is empty then we will not get this folder in Published files)
  4. Now publish the project and make sure that we have logs folder present.
  5. Now when we run the application and if there are any errors, It will be logged in logs folder in server and that helps us in identifying what the actual error is.



In my case the error was something related to Entityframework and sqllite DB

Application startup exception: Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 14: 'unable to open database file'.
   at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
   at Microsoft.Data.Sqlite.SqliteConnection.Open()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteDatabaseCreator.Create()
   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureCreated()
   at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureCreated()

I was getting this error because I am trying to create a SqLite DB in a subfolder and again ASP.Net core was not able to create subfolder. So I manually created the folder and it was resolved.

optionsBuilder.UseSqlite(@"Data Source=C:\Pavan\MyDatabase.db");



Thanks,
Pavan Kumar Aryasomayajulu