ASP.NET Core 3.0: The type or namespace name 'CreateDefaultBuilder' does not exist in the namespace
Take another look at the error message:
The type or namespace name 'CreateDefaultBuilder' does not exist in the namespace 'Template.Host'...
When you write Host.CreateDefaultBuilder
in a namespace of Template.Host
, the compiler assumes you mean Template.Host.CreateDefaultBuilder
.
There's a few options for fixing this:
Nest the
using
statement inside of your namespace:namespace Template.Host { using Microsoft.Extensions.Hosting; // ... }
Alias the
Microsoft.Extensions.Hosting.Host
type inside of your namespace:namespace Template.Host { using Host = Microsoft.Extensions.Hosting.Host; // ... }
Use the fully qualified name for the
Host
type:Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
Host
represents the Generic Host and is preferred over WebHost
in ASP.NET Core 3.0+.