Application is running inside IIS process but is not configured to use IIS server .NET Core 3.0
Asked Answered
L

5

92

I have migrated our application from .NET Core 2.2 to version 3.0. Actually I created the new application in 3.0 from scratch and then copied source code files. Everything looks great but when I try to run the application within Visual Studio 2019 I get the exception:

Application is running inside IIS process but is not configured to use IIS server

Here is my Program.cs

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

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

The error occurs at the line: CreateHostBuilder(args).Build().Run(); It worked fine in .NET Core 2.2 but it doesn't want to run as 3.0. I cannot find anything else that should be done. Something new in the Startup.cs? I don't know.

Lions answered 24/9, 2019 at 12:28 Comment(2)
Remove .UseKestrel(). The migration process is documented, in Migrate from ASP.NET Core 2.2 to 3.0. 3.0 is a major version with expected (and documented) breaking changes. The default hosting model now is in-process activationBurnell
And what if they want to use kestrel?Sumerology
A
130

I also came across this issue while following the documentation https://learn.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio

For your case I have checked and the code below will work, with the call to webBuilder.UseKestrel() removed.

public static IHostBuilder CreateHostBuilder(string[] args) =>
       Host.CreateDefaultBuilder(args)
           .ConfigureWebHostDefaults(webBuilder =>
           {
               webBuilder.UseContentRoot(Directory.GetCurrentDirectory());
               webBuilder.UseIISIntegration();
               webBuilder.UseStartup<Startup>();
           });
Antrorse answered 25/9, 2019 at 6:14 Comment(7)
Yes, leaving out UseKestrel() did the job. Thanks a lot!Lions
BTW, it works, because ConfigureWebHostDefaults does both: UseKestrel and UseIIS internally. Those methods bind IServer to Kestrel or IIS. ServiceProvider works in "last wins" manner. So, if you write UseKestrel - it's last, if you leave it out UseIIS is last.Hospitable
Also, UseIISIntegration is also called inside ConfigureWebHostDefaults.Hospitable
Is it possible to create a "binary" that is compatible to both, IIS and Kestrel? It would be a pity, to create different deployments, just because of these two lines of code...Transferor
This answer works on my end. Thank you!Channing
is there anything that would work for all servers? this is not working on my endUpgrowth
also I'm trying to remove server header which is available only in useKestrel middlewareUpgrowth
J
44

I had the same error then to fix my problem I needed to change webBuilder.UseKestrel(); to ConfigureKestrel(serverOptions => {})

My Program.cs before:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseKestrel();
            webBuilder.UseStartup<Startup>();
        });

My Program.cs fixed:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.ConfigureKestrel(serverOptions =>
            {
            })
            .UseStartup<Startup>();
        });
Josejosee answered 20/8, 2020 at 13:11 Comment(0)
C
27

In my case I ran wrong profile (IIS Express) in Visual Studio by carelessness.

enter image description here

Crumby answered 28/2, 2020 at 8:52 Comment(0)
A
8

As @flam3 suggested, you need to select a profile with correct command.

Open Solution Explorer -> Your Project Name -> Properties -> launchSettings.json file.

The value of the key commandName should be 'Project' instead of 'IIS Express'

So select profile with the name Elsa.Samples.UserRegistration.Web(in my case). See below. Or you may try changing IISExpress to Project on line no 19

Launch Profile

Aalborg answered 29/3, 2021 at 8:21 Comment(0)
W
8

For Visual Studio 2019 and 2022

Go to API project properties: Debug Tab -> General -> Hit "Open Debug launch profiles UI"

enter image description here

Scroll Down to Hosting Model and Select "Out Of process"

enter image description here

Then, you will be able to run your application with no Issues.

Windmill answered 14/2, 2022 at 17:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.