14

After publishing my .net core 2 app on IIS 7.5 I get this error:

an error occurred while starting the application.

Is there any way to force dot net core to submit a accurate error message rather than such general message?

Ehsan Zargar Ershadi
  • 24,115
  • 17
  • 65
  • 95
  • I think the first answer should help you here [asp-net-core-1-1-runs-fine-locally-but-when-publishing-to-azure-says-an-error-o](https://stackoverflow.com/questions/41915522/asp-net-core-1-1-runs-fine-locally-but-when-publishing-to-azure-says-an-error-o) – Arman.Salehi Apr 05 '18 at 08:31
  • Possible dublicate: https://stackoverflow.com/questions/43493259/asp-net-core-publish-error-an-error-occurred-while-starting-the-application/51988150#51988150 – George Kosmidis Aug 24 '18 at 09:21

7 Answers7

31

You can try to start your application directly on your IIS Server via the console.

dotnet myapp.dll

You should get a much more verbose error there.

Yush0
  • 1,547
  • 18
  • 22
  • 2
    Note that if your application is compiled as an exe, you don't need to include `dotnet`, just execute `myapp.exe` – Billy Jo Jun 18 '19 at 16:27
  • or simply run `myapp.exe` by double clicking the exe file. It will crash, showing startup exception on console – Zeeshan Oct 03 '19 at 01:59
8

I found this link helpful: How to troubleshoot: “An error occurred.... In summary:

  1. In the <aspNetCore> element of your web.config, set stdoutLogEnabled to true.
<aspNetCore processPath=".\myapp.exe"
            stdoutLogEnabled="true"
            stdoutLogFile=".\logs\stdout" />
  1. Create your log folder.

    Example: Given stdoutLogFile=".\logs\stdout", create logs\ in your application root directory. .\logs\ is the directory where logs will be stored, and is configurable to your preference. stdout is a static value that'll be prepended to all file names in the log folder.

  2. Run your request and open the log file.

Additional information on the ASP.NET Core module: ASP.NET Core Module

Don't forget to disable logging once done!

Billy Jo
  • 1,326
  • 19
  • 32
4

My problem was simply that IIS didn't had permission to write in the folder that the application files were located.

This is a very bad error to get.

Hope it will help somebody and not waste many hours on it.

Andrei Dobrin
  • 1,164
  • 4
  • 19
  • 35
1

I followed the following steps when I got the error in our environment after deployment.

Server: Windows Server 2016

IIS Version: 10.0

Step1: Check all configs are upto date

Step2: Verify Cors config. We have enabled cors and the list to allow is part of config.

I was able to solve with these two steps.

After deployment it will be mostly with the appsettings.config. Make sure the config is correct. Hope this helps.

Christian Casutt
  • 2,334
  • 4
  • 29
  • 38
draja54
  • 11
  • 1
1

If you deploy the app to the shared hosting, you can not run it via console. therefore I suggest doing the following steps:

  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 also 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.)
  4. The “stdout” part of the value “.\logs\stdout” actually references the filename, not the folder. Which is a bit confusing.
  5. Run your request again, then open the \logs\stdout_*.log file
  6. Have fun ;)

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

B.Habibzadeh
  • 490
  • 6
  • 10
0

Don't get frustrated as the error doesn't give any clue. To get the error there is a simple way

  1. Open command prompt.
  2. Navigate to your published folder location which is mapped to IIS.
  3. Type dotnet yourapplicationddllName.dll
  4. Now open http://localhost:5000 or https://localhost:5001. This will open your application.
  5. Do your thing. you will get the error in the command prompt console.

This method save me several times when some critical releases gets delayed Cheers

BIJIN PALAKKAL
  • 186
  • 1
  • 4
0

If your Program.cs have code to get Some Folder eg : "Image Folder", etc, you need to Create the Folder Manually in your server.

to check the error in the server folder , execute command :

dotnet <yourSolutionName>.dll