Home > other >  Building this implementation of IHostBuilder is not supported
Building this implementation of IHostBuilder is not supported

Time:07-12

I am trying configure IHostBuilder and getting following error.

Building this implementation of IWebHostBuilder is not supported.

I am not sure why this is complaining about IHostBuilder. My IHostBuilder configuration in Program.cs:

 var host = Host.CreateDefaultBuilder(args).
                    UseWindowsService().
                    ConfigureWebHostDefaults(webBuiler =>
                    {
                        webBuiler.UseKestrel(k =>
                        {
                            k.Listen(IPAddress.Parse(componentsModel.LaunchSetting.LaunchIP), componentsModel.LaunchSetting.LaunchHTTPSPort, listenOptions =>
                            {
                                if (certificate != null)
                                {
                                    listenOptions.UseHttps(certificate);
                                }
                            });
                            k.Listen(IPAddress.Parse(componentsModel.LaunchSetting.LaunchIP), componentsModel.LaunchSetting.LaunchPort);
                        }).
                        UseContentRoot(Directory.GetCurrentDirectory()).ConfigureLogging(logging =>
                        {
                            logging.SetMinimumLevel(logLevel);
                            logging.AddDebug();
                            logging.AddFile(f =>
                            {
                                f.LogDirectory = logDirectory;
                                f.FileName = fileName;
                            });
                        }).UseStartup<Startup>()
                        .UseApplicationInsights()
                        .Build()
                        .Run();
                    });

My StackTrace:

System.NotSupportedException
  HResult=0x80131515
  Message=Building this implementation of IWebHostBuilder is not supported.
  Source=Microsoft.AspNetCore.Hosting
  StackTrace:
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.Build()
   at AddonsService.Program.<>c__DisplayClass4_1.<Main>b__0(IWebHostBuilder webBuiler) in C:\Users\Vlad\source\repos\Bill\AddonsService\Program.cs:line 93
   at Microsoft.Extensions.Hosting.GenericHostBuilderExtensions.<>c__DisplayClass0_0.<ConfigureWebHostDefaults>b__0(IWebHostBuilder webHostBuilder)
   at Microsoft.Extensions.Hosting.GenericHostWebHostBuilderExtensions.ConfigureWebHost(IHostBuilder builder, Action`1 configure, Action`1 configureWebHostBuilder)
   at Microsoft.Extensions.Hosting.GenericHostWebHostBuilderExtensions.ConfigureWebHost(IHostBuilder builder, Action`1 configure)
   at Microsoft.Extensions.Hosting.GenericHostBuilderExtensions.ConfigureWebHostDefaults(IHostBuilder builder, Action`1 configure)
   at AddonsService.Program.Main(String[] args) in C:\Users\Vlad\source\repos\Bill\AddonsService\Program.cs:line 89

CodePudding user response:

remove these two lines

  .Build()
  .Run();

it should part of main method

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