Vin*_*nie 6 .net c# swashbuckle.aspnetcore
我似乎无法让 Swashbuckle.AspNetCore.Cli 与我的 .NET Core 3.1 项目一起使用。我已经使用这些指令安装了 Cli ,并且构建项目工作正常。但每当我尝试生成 swagger.json 时,它都会给我提供与无法找到的 appsettings.json 变量相关的未处理异常。使用 Cli 工具运行程序集似乎不会加载我的设置。以前有其他人遇到过这个问题吗?
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
Run Code Online (Sandbox Code Playgroud)
我在 .Net 6 和 Swashbuckle 6.2.3 中遇到了这个问题。我必须检查入口组件,正如评论中所建议的:
AppConfig? configuration = null;
var builder = WebApplication.CreateBuilder(args);
if (Assembly.GetEntryAssembly()?.GetName().Name != "dotnet-swagger")
{
// Had only this line previously
builder.Host.ConfigureAppConfiguration(config => configuration = config.Build().Get<AppConfig>());
}
else
{
configuration = new AppConfig { /* Configure manually for Swagger's use */ };
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1513 次 |
| 最近记录: |