繁体   English   中英

ServiceStack 5.13.0 元数据和 swagger-ui 页面在 .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 包)页面都返回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 之前没有发生这种情况。两个页面都运行良好。 我的启动代码如下:

程序.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();

应用主机.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);
    }
}

AppConfigurator.cs中ServiceStack相关代码

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

我似乎无法弄清楚问题是什么,任何输入都将受到高度赞赏,非常感谢。

在遵循 mythz 的建议后,我想出了如何解决问题。 问题确实是 BrowserLink 和新的热重载功能。

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

我按照此处的说明操作: 如何在 ASP.NET Core (.NET 6, VS 2022) 中禁用浏览器链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM