简体   繁体   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

I've recently started migrating my microservices to .NET 6. I upgraded to ServiceStack 5.13.0 from 5.11.0 and I found out that both the /metadata and the /swagger-ui (from ServiceStack.Api.OpenApi package) pages return HTTP status code 500. I get no exception whatsoever.我最近开始将我的微服务迁移到 .NET 6。我从 5.11.0 升级到 ServiceStack 5.13.0,我发现 /metadata 和 /swagger-ui(来自 ServiceStack.Api.OpenApi 包)页面都返回HTTP 状态代码 500。我没有任何例外。

Note: The rest of the microservice works perfectly fine.注意:微服务的其余部分运行良好。 I can make calls to other endpoints without any issue.我可以毫无问题地拨打其他端点。

However, when I enable debugging logs in ServiceStack, I get the following exceptions whenever I visit either /metadata or /swagger-ui但是,当我在 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)

This did not happen before migrating to .NET 6. Both pages were working perfectly fine.在迁移到 .NET 6 之前没有发生这种情况。两个页面都运行良好。 My startup code is the following:我的启动代码如下:

Program.cs程序.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:应用主机.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 related code in AppConfigurator.cs AppConfigurator.cs中ServiceStack相关代码

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

I can't seem to figure out what the issue is, any inputs will be highly appreciated, thanks a lot.我似乎无法弄清楚问题是什么,任何输入都将受到高度赞赏,非常感谢。

I figured out how to solve the problem after following mythz's advice.在遵循 mythz 的建议后,我想出了如何解决问题。 The issue was indeed BrowserLink and the new hot reload functinality.问题确实是 BrowserLink 和新的热重载功能。

Disabling the hot reload functinality solves the problem.禁用热重载功能可以解决问题。

I followed the instructions here: How to disable Browser Link in ASP.NET Core (.NET 6, VS 2022)我按照此处的说明操作: 如何在 ASP.NET Core (.NET 6, VS 2022) 中禁用浏览器链接

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

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