Search code examples
c#asp.netkestrel

Issue with .ConfigureKestrel() method in .net Core


I'm trying to create a very simple API with .net Core, and am exploring Kestrel. I am following the directions on this MS tutorial: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-2.2

However, when I try to call the ConfigureKestrel method, Visual Studio tells me that "IWebHostBuilder does not contain a definition for 'ConfigureKestrel()' and no accessible extension method for ConfigureKestrel accepting a first argument of the type 'IWebHostBuilder' could be found (are you missing a using directive or an assembly reference?)"

I can't find any info on this, and I'm fairly sure I'm using the right libraries. Any help would be greatly appreciated - code is included:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

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

        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .ConfigureKestrel((context, options) =>
        {
            // Error with ConfigureKestrel method above
        });
    }
}

Solution

  • I have created a sample application from scratch and this compiles:

    using Microsoft.AspNetCore;
    using Microsoft.AspNetCore.Hosting;
    
    namespace WebApplication1
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                CreateWebHostBuilder(args).Build().Run();
            }
    
            public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
                WebHost.CreateDefaultBuilder(args)
                    .UseStartup<Startup>()
                    .ConfigureKestrel((a, b) => { });
        }
    }
    

    Can you check if this example works for you?

    Please also check that you have the latest version of .Net Core, perhaps it was changed? The documentation is 2.2