2

I created a .NET 5, Visual Studio project using the Worker Service template, which creates a Program.cs file containing the Program class with the following method:

public static IHostBuilder CreateHostBuilder(string[] args) =>
   Host.CreateDefaultBuilder(args)
   .ConfigureServices((hostContext, services) =>
   {
      services.AddHostedService<Worker>();
   });

Since I want to specify a Startup class to implement health checks for this application (since it will be deployed to Kubernetes (I’m following this tutorial)), I read there’s the ConfigureWebHostDefaults extension method. However, I get the following error trying to use it:

enter image description here

The code that gives me the error is the following (the one hidden by the error in the above screenshot):

.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); })

This answer seemed to show my situation, but the Microsoft.Extensions.Hosting.Abstractions package doesn’t resolve the issue. I also tried to import the Microsoft.AspNetCore.Hosting and Microsoft.AspNetCore.Hosting packages, without success. I’m already using the Microsoft.Extensions.Hosting package.

Pine Code
  • 2,466
  • 3
  • 18
  • 43

1 Answers1

0

I think it's still in the Microsoft.Extensions.Hosting namespace, but it's now in the Microsoft.AspNetCore assembly.

(The class containing the method is GenericHostBuilderExtensions).

benjamin
  • 1,364
  • 1
  • 14
  • 26