Open abuzaforfagun opened 3 years ago
Using assembly is obsolete and should not be used, controllers with minimal APIs do not work (use Startup.cs), see https://github.com/RicoSuter/NSwag/issues/3794
Hi @RicoSuter I'd appreciate your help:
I get the same error, I'm using version NSwag.MSBuild 13.19 and dotnet7, no minimal APIs.
maybe it's because of this condition on the above mentioned PR not having NET7 ?
my csproj :
`
</Target>`
nswag is default with
"runtime": "Net70",
my program.cs is simple and usual startup-less without even a Main function :
` try { var builder = WebApplication.CreateBuilder(args);
var healthCheckBuilder = builder.Services.AddHealthChecks();
_ = builder.Services.AddSingleton<IServiceCollection>(builder.Services);
_ = builder.Services.AddOptions();
_ = builder.Host.ConfigureServices((hostContext, services) =>
{
_ = services.AddSingleton<IExampleService, gt178.Services.ExampleService>();
_ = services.AddSingleton<gt178.Repositories.Interfaces.IExampleRepository, IExampleRepository>();
});
var app = builder.Build();
app.Run();
} catch (Exception e) { //log }
///
the error :
System.InvalidOperationException: NSwag requires the assembly gt178.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null to have either an BuildWebHost or CreateWebHostBuilder/CreateHostBuilder method. See https://docs.micros
oft.com/en-us/aspnet/core/fundamentals/hosting?tabs=aspnetcore2x for suggestions on ways to refactor your startup type.
at NSwag.Commands.ServiceProviderResolver.GetServiceProvider(Assembly assembly) in //src/NSwag.Commands/HostApplication.cs:line 87
at NSwag.Commands.Generation.OpenApiGeneratorCommandBase`1.GetServiceProvider(AssemblyLoader assemblyLoader) in //src/NSwag.Commands/Commands/Generation/OpenApiGeneratorCommandBase.cs:line 313
at NSwag.Commands.Generation.AspNetCore.AspNetCoreToSwaggerCommand.RunIsolatedAsync(AssemblyLoader assemblyLoader) in //src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiCommand.cs:line 323
at NSwag.Commands.IsolatedCommandBase`1.IsolatedCommandAssemblyLoader.Run(String commandType, String commandData, String[] assemblyPaths, String[] referencePaths) in //src/NSwag.Commands/Commands/IsolatedCommandBase.cs:line 76
at NSwag.Commands.IsolatedCommandBase1.RunIsolatedAsync(String configurationFile) in /_/src/NSwag.Commands/Commands/IsolatedCommandBase.cs:line 61 at NSwag.Commands.IsolatedSwaggerOutputCommandBase
1.RunAsync(CommandLineProcessor processor, IConsoleHost host) in //src/NSwag.Commands/Commands/IsolatedSwaggerOutputCommandBase.cs:line 51
at NSwag.Commands.Generation.AspNetCore.AspNetCoreToSwaggerCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in //src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiCommand.cs:line 98
at NSwag.Commands.NSwagDocumentBase.GenerateSwaggerDocumentAsync() in //src/NSwag.Commands/NSwagDocumentBase.cs:line 275
at NSwag.Commands.NSwagDocument.ExecuteAsync() in //src/NSwag.Commands/NSwagDocument.cs:line 81
at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in //src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 85
at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in //src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 32
at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
at NSwag.Commands.NSwagCommandProcessor.ProcessAsync(String[] args) in /_/src/NSwag.Commands/NSwagCommandProcessor.cs:line 61
Project Option: It generates empty Swagger Specification. Assembly Option: It return an error about BuildWebHost or CreateWebHostBuilder not found.
Steps to reproduce:
NSwagger Studio Version: 13.14.7.0