5
votes

This is the second project I have updated from ASP.Net Core 2.2 to 3.1. The first one runs fine. The second one runs fine in Visual Studio (2019), but when you publish it and run it from dotnet CLI the console just hangs indefinitely, no output in the console and I have enabled stdout and the output file is zero bytes.

The solution is hosted within IIS and when I try and run it through IIS I get the following entries in the application event log:

Application '/LM/W3SVC/2/ROOT' with physical root 'D:\wwwroot\InclusionService_UAT\' failed to start process with commandline 'C:\Program Files\dotnet\dotnet.exe .\InclusionService.Web.dll' at stage 'PostStartCheck', ErrorCode = '0x8027025a', assigned port 12973, retryCounter '1'.

and

Application '/LM/W3SVC/2/ROOT' with physical root 'D:\wwwroot\InclusionService_UAT\' failed to start process with commandline 'C:\Program Files\dotnet\dotnet.exe .\InclusionService.Web.dll' with multiple retries. Failed to bind to port '35033'. First 30KB characters of captured stdout and stderr logs from multiple retries: nothing more shown

This is my Program.cs which I have exactly the same in my other migrated solution:

public static void Main(string[] args)
{
    var builder = new HostBuilder()
       .ConfigureWebHostDefaults(opt =>
       {
             opt.UseStartup<Startup>();
             opt.UseIISIntegration();
        });

    var host = builder.Build();
    host.Start();
}

It would be much easier to debug if there was some output, but there's nothing to go on.

4
Have you tried disabling everything in Startup.cs to see if the issue might be related to some service registration?Andrew Simon
@AndrewSimon I have forced an exception to be thrown at the end of ConfigureServices() and Configure() methods in Startup.cs and both times the exception is displayed in the console output which leads me to believe the service registrations are ok ...Jason Goodwin
If it's getting to the end of Startup.cs then it should be loading correctly. Is the error occuring when you call a specific endpoint? What is the first request where it loads up the application?Andrew Simon
@AndrewSimon The error occurs at startup. When I try and spin the app up in IIS I just get the HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure error.Jason Goodwin
Have you checked the Application or System event log?Andrew Simon

4 Answers

3
votes

Please see Yush0's answer for the correct solution.

The problem was down to using the new IHost instead of the existing IWebHost in Program.cs.

It's worth noting that IHost worked fine with the migration to .NET Core 3.1 with Razor Pages, but this solution was and MVC application and would only work in IIS with IWebHost.

When I put the original code back as below, the application fired up straight away in IIS:

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseIISIntegration();
}
1
votes

I also had to make sure the web.config is correct since it doesn't get overwritten on publish anymore (at least when selfcontained). It should look as follows:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath=".\MyApp.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

Specifying the hostingModel did the trick for me.

program.cs didn't seem to make a difference, but it looks as follows (without deprecated WebHostBuilder):

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseContentRoot(Directory.GetCurrentDirectory())
            .UseStartup<Startup>()
            .UseIIS();
        });
0
votes

So about that, I'm currently doing the same thing. I had to use UseIIS() and not UseIISIntegration().

Here's the excerpt:

.ConfigureWebHostDefaults(webBuilder => 
{ 
    webBuilder.UseStartup<T>().UseIIS(); 
}

Also, make sure the hosting bundle has been updated on your IIS server:

0
votes

Hi I had similar issue did not work all above mentioned process. I had to create a new .net 3.1 core project then migrated code from 2.2 to new created project that solved my problem and running successfully. after published i have seen in version 3.1 has create few new folders.

Hope that may help someone Thanks