What am I using:
I created a new ASP.NET Core Web API project targeting netcoreapp3.0 and I get the following error:
The type or namespace name 'CreateDefaultBuilder' does not exist in the namespace 'Template.Host' (are you missing an assembly reference?)
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+.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With