ServiceStack 5.13.0 元数据和 swagger-ui 页面 return .NET 6 迁移后出现 500 错误

ServiceStack 5.13.0 metadata and swagger-ui pages return a 500 error after .NET 6 migration

我最近开始将我的微服务迁移到 .NET 6。我从 5.11.0 升级到 ServiceStack 5.13.0,我发现 /metadata 和 /swagger-ui(来自ServiceStack.Api.OpenApi package) pages return HTTP 状态代码 500。我没有任何异常。

注意:微服务的其余部分工作得很好。我可以毫无问题地调用其他端点。

但是,当我在 ServiceStack 中启用调试日志时,每当我访问 /metadata 或 /swagger-ui

时,都会出现以下异常
[Info] Service is starting up.
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:7058
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5058
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Projects\chargeleo.users.managementservice\Chargeleo.Users.ManagementService.Web\
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HMD882JRAOH5", Request id "0HMD882JRAOH5:00000007": An unhandled exception was thrown by the application.
      System.InvalidOperationException: An asynchronous socket operation is already in progress using this SocketAsyncEventArgs instance.
         at System.Net.Sockets.SocketAsyncEventArgs.ThrowForNonFreeStatus(Int32 status)
         at System.Net.Sockets.SocketAsyncEventArgs.set_BufferList(IList`1 value)
         at Microsoft.WebTools.BrowserLink.Net.SocketAdapter.SendAsync(IList`1 buffers)
      --- End of stack trace from previous location ---
         at Microsoft.WebTools.BrowserLink.Net.DelayConnectingHttpSocketAdapter.Microsoft.WebTools.BrowserLink.Net.IHttpSocketAdapter.CompleteRequestAsync()
         at Microsoft.WebTools.BrowserLink.Net.ScriptInjectionFilterStream.WaitForFilterCompleteAsync()
         at Microsoft.WebTools.BrowserLink.Net.BrowserLinkMiddleware.ExecuteWithFilterAsync(IHttpSocketAdapter injectScriptSocket, String requestId, HttpContext httpContext)
         at Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware.InvokeAsync(HttpContext context)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HMD882JRAOH6", Request id "0HMD882JRAOH6:00000001": An unhandled exception was thrown by the application.
      System.InvalidOperationException: Attempted to send data when a send was already in progress.
         at Microsoft.WebTools.BrowserLink.Net.DelayConnectingHttpSocketAdapter.Microsoft.WebTools.BrowserLink.Net.IHttpSocketAdapter.CompleteRequestAsync()
         at Microsoft.WebTools.BrowserLink.Net.ScriptInjectionFilterStream.WaitForFilterCompleteAsync()
         at Microsoft.WebTools.BrowserLink.Net.BrowserLinkMiddleware.ExecuteWithFilterAsync(IHttpSocketAdapter injectScriptSocket, String requestId, HttpContext httpContext)
         at Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware.InvokeAsync(HttpContext context)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

迁移到 .NET 6 之前不会发生这种情况。两个页面都运行良好。我的启动代码如下:

Program.cs

using System.Diagnostics;
using ServiceStack;

var builder = WebApplication.CreateBuilder(args);

Debug.WriteLine(builder.Configuration["Environment"]);

var app = builder.Build();
app.UseServiceStack(new AppHost(builder.Configuration["Environment"]));

if (!app.Environment.IsDevelopment())
{
    app.UseHsts();
    app.UseHttpsRedirection();
}

app.Run();

AppHost.cs:

using Funq;
using ServiceStack;
using Chargeleo.Users.ManagementService.Common;

namespace Chargeleo.Users.ManagementService.Web;

public class AppHost : AppHostBase
{
    private AppConfigurator _configurator;
    private readonly string _environment;

    public AppHost(string environment) : base(ServiceConstants.ServiceName, typeof(AppConfigurator).Assembly)
    {
        _environment = environment;
    }

    public override void Configure(Container container)
    {
        _configurator = new AppConfigurator(this, _environment);
    }
}

ServiceStack相关代码在AppConfigurator.cs

appHost.SetConfig(new HostConfig { DebugMode = true });
appHost.Plugins.Add(new CorsFeature());
appHost.Plugins.Add(new ValidationFeature());
appHost.Plugins.Add(new OpenApiFeature());

我似乎无法弄清楚问题出在哪里,非常感谢任何意见,非常感谢。

在听了mythz的建议后,我想出了解决问题的方法。问题确实出在 BrowserLink 和新的热重载功能上。

禁用热重载功能解决了问题。

我按照此处的说明操作: