3

I try to run integration tests and get this error

System.InvalidOperationException: The entry point exited without ever building an IHost. at Microsoft.Extensions.Hosting.HostFactoryResolver.HostingListener.CreateHost() at Microsoft.Extensions.Hosting.HostFactoryResolver.<>c__DisplayClass10_0.b__0(String[] args) at Microsoft.AspNetCore.Mvc.Testing.DeferredHostBuilder.Build() at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateHost(IHostBuilder builder) at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.ConfigureHostBuilder(IHostBuilder hostBuilder) at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.EnsureServer() at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateDefaultClient(DelegatingHandler[] handlers) at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateDefaultClient(Uri baseAddress, DelegatingHandler[] handlers) at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateClient(WebApplicationFactoryClientOptions options) at Ptco.System.IntegrationTests.Infrastructure.IntegrationTestsWebFactory.CreteManagedClient() in C:\Users\nemes\Documents\GitHub\ptco.app\System\Ptco.System.IntegrationTests\Infrastructure\IntegrationTestsWebFactory.cs:line 249

Row 249 is

private HttpClient CreteManagedClient() =>
        CreateClient(new WebApplicationFactoryClientOptions
        {
            BaseAddress = new Uri(_configuration.GetValue<string>("IntegrationServerBaseUri"))
        });

That is called like this

     public IntegrationTestsWebFactory()
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
        {
            _configurationPath = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json");
            _configuration = BuildConfiguration();
            ManagedHttpClient = CreteManagedClient();
        }

How I can solve this error?

Eugene Sukh
  • 2,357
  • 4
  • 42
  • 86
  • You are sending a request to the URL in your configuration file (IntegrationServerBaseUri) and the server is refusing the connection. There are many reason for the server to refuse a connection. Make sure the request has the proper format and any credentials that may be required. You need to read the documentation on the server to verify the format of the request is proper. – jdweng Jun 25 '22 at 14:53

1 Answers1

3

It happens to me because I use serilog with CreateBootstrapLogger().

Here is the detail discussion https://github.com/serilog/serilog-aspnetcore/issues/289

To me, it works fine with CreateLogger. Check if really need CreateBootstrapLogger here https://nblumhardt.com/2020/10/bootstrap-logger/#why-cant-we-just-do-both

maxisam
  • 21,975
  • 9
  • 75
  • 84
  • 1
    This error doesn't come from Serilog though right? – Victorio Berra Mar 02 '23 at 03:18
  • sorry, I am not sure at this point. – maxisam Mar 02 '23 at 15:30
  • 1
    So I found more info. Hopefully this helps someone. The error "The entry point exited without ever building an IHost" generally happens when the host failed to start because it crashed. A similar error is "The server has not been started or no web application was configured.". The real error might be in the logs or might not be. This CAN be related to Serilog but not ALWAYS. This can happen during integration tests that run in parallel because like the github issue explains Serilog CreateBootstrapLogger() is a stateful operation and does some tricky things during startup. – Victorio Berra Mar 03 '23 at 17:02