gpt4 book ai didi

c# - 入口点在没有构建 IHost 的情况下退出

转载 作者:行者123 更新时间:2023-12-05 05:39:13 35 4
gpt4 key购买 nike

我尝试运行集成测试并得到这个错误

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

第249行是

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

是这样称呼的

     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();
}

我该如何解决这个错误?

最佳答案

它发生在我身上,因为我将 serilog 与 CreateBootstrapLogger() 一起使用。

这里是详细讨论https://github.com/serilog/serilog-aspnetcore/issues/289

对我来说,它与 CreateLogger 配合使用效果很好。在此处检查是否真的需要 CreateBootstrapLogger https://nblumhardt.com/2020/10/bootstrap-logger/#why-cant-we-just-do-both

关于c# - 入口点在没有构建 IHost 的情况下退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72754824/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com