At the moment I'm trying to update a project from dotnet 2.1 to 3.1. To do that and avoid exceptions I've had to upgrade swagger, and everything works, except swagger. For some unknown reason Swagger returns this exception when I try to produce it's json mapping. I'm making these changes in a Catalina macOs, macBook Pro.
The command "dotnet swagger tofile --output .\autogenerated-api.json bin/Debug/netcoreapp3.1/App.dll v2" exited with code 134.
...
Unhandled exception. System.TypeLoadException: Could not load type 'Swashbuckle.AspNetCore.Swagger.SwaggerDocument' from assembly 'Swashbuckle.AspNetCore.Swagger, Version=5.6.3.0, Culture=neutral, PublicKeyToken=62657d7474907593'.
at Swashbuckle.AspNetCore.Cli.Program.<>c.<Main>b__0_3(IDictionary`2 namedArgs)
at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args)
at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args)
at Swashbuckle.AspNetCore.Cli.Program.Main(String[] args)
So far I haven't found any information about that exception specifically. What's going wrong?. I'm using latest Swagger along with a pretty plain setting:
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.6.3" />
...
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="dotnet swagger tofile --output .\autogenerated-api.json $(OutputPath)$(AssemblyName).dll v2" />
And the setting in Startup.cs:
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v2", new OpenApiInfo { Title = "App Api", Version = "v2"});
});
...
if (env.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v2/swagger.json", $"{nameof(App)} API V2");
c.InjectStylesheet("/brand.css");
});
}
The idea naturally is to generate a json mapping on every development run. Still wondering why Swagger is trying to reach a package it doesn't have (SwaggerDocument).
Thanks.
It could be pointing to different version of CLI.
Try the following steps.
Install the 5.6.3 CLI