I have a WebApi Project in .Net 5 and have already been using Swagger with default setup (services.AddSwaggerGen() in ConfigureServices method & app.UseSwagger() and app.UseSwaggerUI() in Configure method in Startup.cs) without any issues.
Now I decided to create Swagger Files via Swashbuckle.AspNetCore.Cli.
I created manifest file:
.net new tool-manifest
and then installed Swashbuckle.AspNetCore.Cli:dotnet tool install --version 6.2.3 Swashbuckle.AspNetCore.Cli
All is fine until here. Also checked to see if it is working via dotnet swagger tofile --help, and it is.
Now when I want to create json file via dotnet swagger tofile --output api.json bin\Debug\net5.0\MyApiApi.dll v1, I get
System.InvalidOperationException: No service for type 'Swashbuckle.AspNetCore.Swagger.ISwaggerProvider' has been registered. at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Swashbuckle.AspNetCore.Cli.Program.<>c.b__0_4(IDictionary
2 namedArgs) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\Program.cs:line 82 at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable1 args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\CommandRunner.cs:line 68 at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\CommandRunner.cs:line 59 at Swashbuckle.AspNetCore.Cli.Program.Main(String[] args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\Program.cs:line 121
exception. I have not been able to detect the cause. I am already using
- Swashbuckle.AspNetCore (6.2.3)
- Swashbuckle.AspNetCore.Swagger (6.2.3)
- Swashbuckle.AspNetCore.Annotations (6.2.3),
- Swashbuckle.AspNetCore.Newtonsoft (6.2.3)
Has anyone any idea what could be causing that problem? Note that it is different than "unable to resolve service" error, which could be resolved by adding services.AddSwaggerGen() in Startup.cs. I already use that since Swagger is already in use in this project.