I’m not sure if this solves OP’s problem, but this error also occurs when you use Swashbuckle 4 in .Net Core 3. The solution is to use Swashbuckle 5.
(use command install-package Swashbuckle.AspNetCore) to have in .csproj
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
Then you’ll need to upgrade it in Startup.cs. Generally that involves prefixing classes that don’t compile with OpenApi e.g.
options.SwaggerDoc("v1" new Info ...
becomes
options.SwaggerDoc("v1", OpenApiInfo
Also OpenApiSecurityScheme becomes ApiKeyScheme
See also docs at https://github.com/domaindrivendev/Swashbuckle.AspNetCore