.NET 6:不允许同步操作。改为调用 WriteAsync 或将 AllowSynchronousIO 设置为 true

.NET 6: synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead

我已经在 .NET 6.0 中实现了一个控制台应用程序。我已经在启动时 AllowSynchronousIO = true 但仍然遇到相同的错误。下面是我在启动时添加的代码 class 以允许同步为真。

    services.Configure<IISServerOptions>(options =>
    {
        options.AllowSynchronousIO = true;
    });

在你的 CreateHostBuilder (Program.cs) 中添加这个

.ConfigureWebHostDefaults(builder =>
{
    builder.ConfigureKestrel(options =>
    {
        options.AllowSynchronousIO = true;
    });
    builder.UseStartup<Startup>();
}

不确定如何使用最小的 API