Swashbuckle.AspNetCore: swagger tofile getting an error on System.Runtime.Loader

Hi all, great tool idea. I’m trying to get it working. Right now I have the latest 5.0 installed.

doing a dotnet publish -o ./pub swagger tofile --output .\swagger.json .\pub\bin\myfile.dll v1

And getting a: Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly ‘System.Runtime.Loader, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at Swashbuckle.AspNetCore.Cli.Program.<>c.<Main>b__0_3(IDictionary2 namedArgs) 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 68 at Swashbuckle.AspNetCore.Cli.Program.Main(String[] args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\Program.cs:line 106

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 29 (8 by maintainers)

Most upvoted comments

If it helps any body you can resolve this issue by using the right version of dotnet sdk. If your project uses dotnet 2.1 as target run time, you should use the same to install the tool and also running the swagger generation command. Thats how this error resolved for me. The developers have put this as a note too in the documentation.

I’ve been battling with this issue myself. It appears to occur when you have dotnet 3.0 installed on your system, and you’re trying to extract Open API specs out of a Startup Assembly that targets dotnet 2.*.

I assume when you invoke the swagger cli tool it’s using dotnet 3.0 to host the tool, but then it has to load a dotnet 2.* startup assembly to extract the specs, and somewhere in this process it encounters assembly loading issues because of it.

@riker09 Add a nuget.config file like this: <?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <!--To inherit the global NuGet package sources remove the <clear/> line below --> <clear /> <add key="nuget" value="https://api.nuget.org/v3/index.json" /> <add key="domaindriverdev" value="https://www.myget.org/F/domaindrivendev/api/v3/index.json" /> </packageSources> </configuration>

@domaindrivendev, I’ve tested my mwe with 5.4.0-preview-1253 and the Cli tool now works on the project targeting netcoreapp2.2 as well. See updated version: https://github.com/nattomi/SwaggerCliFailMwe Will test and see if it works on my real project too.

I’m seeing this issue as well when I tried using the 5.0 CLI tool downloaded from nuget.

I tried building the tool locally to debug, then I got a similar-but-different error:

$ swagger.exe tofile --output test.json "C:\Users\rleonar7\dev\UO.CAS.PSY.Duckling\UO.CAS.PSY.Duckling\bin\Release\netcoreapp2.2\UO.CAS.PSY.Duckling.dll" 1.0.0

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.AspNetCore.Hosting.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at Swashbuckle.AspNetCore.Cli.Program.<>c.<Main>b__0_3(IDictionary`2 namedArgs)
   at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args) in C:\Users\rleonar7\dev\Swashbuckle.AspNetCore\src\Swashbuckle.AspNetCore.Cli\CommandRunner.cs:line 68
   at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args) in C:\Users\rleonar7\dev\Swashbuckle.AspNetCore\src\Swashbuckle.AspNetCore.Cli\CommandRunner.cs:line 59
   at Swashbuckle.AspNetCore.Cli.Program.Main(String[] args) in C:\Users\rleonar7\dev\Swashbuckle.AspNetCore\src\Swashbuckle.AspNetCore.Cli\Program.cs:line 106