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?
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.
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();
<aspNetCore stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
Could not create stdoutLogFile C:\inetpub... ErrorCode = -2147024891.
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
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:
Properties
Build
tab 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/