Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'Microsoft.OpenApi'... while using Swashbuckle.AspNetCore.Cli

I'm getting the subject error message while using the sample MS PowerShell script from the article Generating API clients using AutoRest when the following command line

dotnet swagger "tofile" --output "../../res/swagger.json" "../Sample.Api/bin/Debug/netcoreapp2.1/Sample.Api.dll" v1

is executed. Solution?

FYI: Swashbuckle.AspNetCore.Cli entry source code is located here: Swashbuckle.AspNetCore/src/Swashbuckle.AspNetCore.Cli/Program.cs

UPDATE

I should have posted the full text of runtime error message - here it is:

At C:\Tests\Swashbuckle\build.ps1:8 char:1
+ dotnet swagger "tofile" --output "../../res/swagger.json" "../Sample. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

Unhandled Exception:

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.OpenApi, 
     Version=1.1.1.0, Culture=neutral, PublicKeyToken=3f5743946376f042'. 
     The system cannot find the file specified.
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)
like image 643
ShamilS Avatar asked Oct 22 '25 17:10

ShamilS


2 Answers

I have used the following to get rid of this issue.

Upgraded swagger to 5.0.0-rc3, my csproj looks like this

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc3" />
  </ItemGroup>

Then I installed the swagger cli using following code as you must have installed

dotnet tool install -g swashbuckle.aspnetcore.cli --version 5.0.0-rc3

And finally running the command

swagger "tofile" --output "../../res/swagger.json" "../Sample.Api/bin/Debug/netcoreapp2.1/Sample.Api.dll" v1

make sure you have swagger in your path after running the above command.

like image 177
Naveen Motwani - AIS Avatar answered Oct 25 '25 05:10

Naveen Motwani - AIS


The issue solved by referencing v.4.0.1 (or v.5.0.0-beta) of Swashbuckle.AspNetCore and Swashbuckle.AspNetCore.Annotations packages and of Swashbuckle.AspNetCore.Cli tool:

...
<ItemGroup>
  <PackageReference Include="Microsoft.AspNetCore.App" />
   <PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
   <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="4.0.1" />
</ItemGroup>

 <ItemGroup>
    <DotNetCliToolReference Include="Swashbuckle.AspNetCore.Cli" Version="4.0.1" />
 </ItemGroup>
like image 45
ShamilS Avatar answered Oct 25 '25 06:10

ShamilS