ASP.Net Core solution migrated from 2.2 to 3.1 won't run when published

5

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.

asp.net
asp.net-core
iis
asked on Stack Overflow Dec 31, 2019 by Jason Goodwin • edited Dec 31, 2019 by Jason Goodwin

4 Answers

3

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();
}
answered on Stack Overflow Jan 2, 2020 by Jason Goodwin • edited Oct 5, 2020 by Jason Goodwin
1

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();
        });
answered on Stack Overflow Jun 19, 2020 by Yush0 • edited Aug 21, 2020 by Yush0
0

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:

answered on Stack Overflow Dec 31, 2019 by b.pell
0

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

answered on Stack Overflow Mar 11, 2020 by Ahsanul

User contributions licensed under CC BY-SA 3.0