6
votes

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?

4

4 Answers

9
votes

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.

7
votes

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=".\logs\stdout">
      <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();
2
votes
  1. try to enable logging in web.config

<aspNetCore stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />

  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:\inetpub\website

in my case it works fine from another drive but it does not work with C:\inetpub\website 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

-3
votes

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/