2

I deployed a API .NET Core 5 service with the Publish feature. When I start the service with cmd with command dotnet <service-name>.dll, it runs but I cannot make API request. When I start it with IIS, it shows me the following error

HTTP Error 500.30 - ASP.NET Core app failed to start

Common solutions to this issue:
- The app failed to start
- The app started but then stopped
- The app started but threw an exception during startup

Troubleshooting steps:

- Check the system event log for error messages
- Enable logging the application process' stdout messages
- Attach a debugger to the application process and inspect

I searched around the internet this error, but I didn't find a solution for my problem. This is my program.cs

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder
            .UseNLog()
            //.UseContentRoot(Directory.GetCurrentDirectory())
            .UseKestrel()
            .UseIISIntegration()
            .UseStartup<Startup>();
            //.Build();
        });

Errors from EventViewer

.NET Runtime

Application: w3wp.exe
CoreCLR Version: 5.0.721.25508
.NET Version: 5.0.7
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException: Application is running inside IIS process but is not configured to use IIS server.
   at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at LogService.Program.Main(String[] args) in C:\DEV\LogService\LogService.API\Program.cs:line 19

IIS AspNetCode Module V2

Application '/LM/W3SVC/2/ROOT' with physical root 'C:\LogService\' hit unexpected managed exception, exception code = '0xe0434352'. First 30KB characters of captured stdout and stderr logs:
crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
      Application startup exception
      System.InvalidOperationException: Application is running inside IIS process but is not configured to use IIS server.
         at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
         at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
         at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
Unhandled exception. System.InvalidOperationException: Application is running inside IIS process but is not configured to use IIS server.
   at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at LogService.Program.Main(String[] args) in C:\DEV\LogService\LogService.API\Program.cs:line 19

Application '/LM/W3SVC/2/ROOT' with physical root 'C:\LogService\' failed to load coreclr. Exception message:
CLR worker thread exited prematurely
15
  • And are there any errors in any logs? (You may find it easier to get at the logs if you skip IIS, just for starting off.) Commented Jun 29, 2021 at 14:46
  • When you run in VS/VS Code does it works? Commented Jun 29, 2021 at 14:55
  • I experienced this because I had a buggy version of .NET Core 2.2 hosting package installed. It hosed out all other runtimes. I don't recall which one, but I updated it to the latest 2.2.x version and that took care of it for all other runtimes. Honestly though, this could be so many things.... Commented Jun 29, 2021 at 15:31
  • 1
    Did you set .NET CLR Version to No Managed Code for application pool? Commented Jun 29, 2021 at 17:21
  • @JonSkeet I have 3 error logged, but they are the same type Application: w3wp.exe CoreCLR Version: 5.0.721.25508 .NET Version: 5.0.7 Description: The process was terminated due to an unhandled exception. Exception Info: System.InvalidOperationException: Application is running inside IIS process but is not configured to use IIS server. Commented Jun 30, 2021 at 6:58

1 Answer 1

2

It works with current configuration

public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder
                .UseNLog()
                //.UseContentRoot(Directory.GetCurrentDirectory())
                //.UseKestrel()
                .UseIISIntegration()
                .UseIIS()
                .UseStartup<Startup>();
                //.Build();
            });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.