ASP.NET Core publish error: An error occurred while starting the application

I tried to publish my ASP.NET Core application on Windows Server 2008 R2 but I get this error:
“An error occurred while starting the application.”

Without any more description!

What can I do?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Please take a look at this post: https://scottsauber.com/2017/04/10/how-to-troubleshoot-an-error-occurred-while-starting-the-application-in-asp-net-core-on-iis which will give you a good starter kit to get basic log informations when this kind of error appear.
It may be a bad startup configuration or related to the .NET Core runtime installed but very difficult to say without more technical information.

Method 2

This is not a real error. You have to find the real error. To see real error do the below. Remember you have to undo these change once you identify the problem and fix it. You should not show real error to end users.

On your dev environment, Try adding/updating this to web.config to see the real error

<aspNetCore processPath=".MyApplication.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".logsstdout">
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
      </environmentVariables>
    </aspNetCore>

In your program.cs add/update below to see real error

public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .CaptureStartupErrors(true)
                .UseSetting("detailedErrors", "true")
                .UseStartup<Startup>()
                .Build();

Method 3

  1. try to enable logging in web.config

<aspNetCore stdoutLogEnabled=”true” stdoutLogFile=”.logsstdout” />

  1. if no logs, check event viewer there will be something like:

Could not create stdoutLogFile C:inetpub… ErrorCode = -2147024891.

  1. Try to setup website on another drive e.g. D:inetpubwebsite

in my case it works fine from another drive but it does not work with C:inetpubwebsite
I suppose this is kind of security permissions trouble.

If it does not help you should at least see the logs that lead you further.

Although i’m Administrator on the pc and other websites under .NET Framework 4.7.1 are running OK from C:inetpub the asp.net core site has the issue

Method 4

Althouth there many things that could go wrong and the proper way is to actually troubleshoot the error, my case was simpler:

I forgot to configure the release output path for Swagger

You can to that by following these steps:

  1. Right click your project
  2. Click Properties
  3. Click on the Build tab
  4. And at the Output section check the XML documentation file checkbox.

This will autocomplete the path with an XML file, but you can change that to whatever you want.

I copy-paste the solution from https://mycodepad.wordpress.com/2018/08/23/publishing-asp-net-core-an-error-occurred-while-starting-the-application/


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x