I have a class public class CustomWebApplicationFactory : WebApplicationFactory<Startup> that have a method
protected override IHostBuilder CreateHostBuilder()
{
return base.CreateHostBuilder().UseEnvironment("Development").UseLogDefaults();
}
After deleting from Program.cs this code
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureAppConfiguration((context, config) =>
{
var builtConfig = config.Build();
/*code here*/
})
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
The CreateHostBuilder method started to throw a null reference exception.
If I delete CreateHostBuilder override method then in tests appears an exception
The entry point exited without ever building an IHost.
Moving the code from Program to CreateHostBuilder did not help.
Startup class is untoched, only deleting IHostBuilder CreateHostBuilder causes the error