Swashbuckle Swagger 生成器:StringBuilder 内存不足

问题描述 投票:0回答:1

我们有一个相当大的 ASP.NET Boilerplate .NET Core 3.1 项目,Swashbuckle 在生成 Swagger JSON 时似乎内存不足。

我们遇到以下错误:

RequestAborted: Exception of type 'System.OutOfMemoryException' was thrown.. Request Path: /swagger/v1/swagger.json
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Text.StringBuilder.ToString()
   at System.IO.StringWriter.ToString()
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.RespondWithSwaggerJson(HttpResponse response, OpenApiDocument swagger)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext()

自然这表明

StringBuilder
无法处理JSON字符串的大小。我不知道
StringBuilder
有任何特定的内存限制,所以不确定为什么会失败。

c# stringbuilder aspnetboilerplate swashbuckle.aspnetcore
1个回答
0
投票

我们跟踪了这个问题,它与我们的控制器/应用程序服务上的以下方法有关。

public MyEnum GetMyEnum(MyDto myDto, long? someValue = null)

看来默认参数值就是原因。我们可以通过将该方法标记为

private
来消除这种依赖性。

© www.soinside.com 2019 - 2024. All rights reserved.