89

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.

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
Ondrej Vencovsky
  • 3,188
  • 9
  • 28
  • 34
  • 25
    Remove `.UseKestrel()`. The migration process is documented, in [Migrate from ASP.NET Core 2.2 to 3.0](https://learn.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio). 3.0 is a major version with expected (and documented) breaking changes. The default hosting model now is [in-process activation](https://learn.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#in-process-hosting-model) – Panagiotis Kanavos Sep 24 '19 at 14:59
  • 1
    And what if they want to use kestrel? – Greg Graham Dec 29 '21 at 22:18

5 Answers5

127

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>();
           });
peregrination
  • 2,460
  • 1
  • 25
  • 21
Satyajit
  • 2,150
  • 2
  • 15
  • 28
40

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>();
        });
Rodolfo Luna
  • 829
  • 9
  • 19
26

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

enter image description here

flam3
  • 1,897
  • 2
  • 19
  • 26
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

VivekDev
  • 20,868
  • 27
  • 132
  • 202
6

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.

David Castro
  • 1,773
  • 21
  • 21