domaindrivendev / Swashbuckle.AspNetCore

Swagger tools for documenting API's built on ASP.NET Core
MIT License
5.2k stars 1.3k forks source link

Could not load file or assembly Swashbuckle.AspNetCore.Swagger for CLI on GitHub Action #2022

Closed fabich closed 3 years ago

fabich commented 3 years ago

Hi

After updating the CLI from 5.4.1 to 6.0.7 we are getting the following error on our GitHub Action build:

Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Swashbuckle.AspNetCore.Swagger, Version=6.0.7.0, Culture=neutral, PublicKeyToken=62657d7474907593'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
File name: 'Swashbuckle.AspNetCore.Swagger, Version=6.0.7.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) 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 111

Our GitHub Action:

name: Run OpenAPI diff check

on: [pull_request]

jobs:
  create-old-files:
    name: Create OLD spec files
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          path: <Project>
          ref: develop
          fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
      - name: Create Result Directory
        run: mkdir src
      - name: Setup .NET Core
        uses: actions/setup-dotnet@v1
        with:
          source-url: https://nuget.pkg.github.com/<Project>/index.json
        env:
          NUGET_AUTH_TOKEN: ${{secrets.GPR_READ}}
      - name: Restore
        run: dotnet restore
        working-directory: ./<Project>
      - name: Build
        run: dotnet build
        working-directory: ./<Project>
      - name: Install Swashbuckle.AspNetCore.Cli
        run: |
          dotnet new tool-manifest
          dotnet tool install Swashbuckle.AspNetCore.Cli --version 6.0.7
      - name: Create OpenAPI specification files
        working-directory: ./<Project>/<Project>.APP
        run: |
          dotnet swagger "tofile" --output "../../src/pdf.json" "./bin/Debug/net5.0/<Project>.APP.dll" pdf
      - name: Copy OpenAPI specification files
        run: cp ./<Project>/<Project>.APP/*.json ../src/
        working-directory: ./<Project>
      - name: Upload OpenAPI specification files
        uses: actions/upload-artifact@v1
        with:
          name: old-files
          path: src

The .csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
    <LangVersion>latest</LangVersion>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <NoWarn>1591;</NoWarn>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="pdf.js">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.17.0" />
    <PackageReference Include="Autofac" Version="6.1.0" />
    <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
    <PackageReference Include="FluentValidation" Version="9.5.1" />
    <PackageReference Include="FluentValidation.AspNetCore" Version="9.5.1" />
    <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.3" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.NodeServices" Version="3.1.12" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.3" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.0.7" />
    <PackageReference Include="Microsoft.AspNetCore.AzureAppServicesIntegration" Version="5.0.3" />
  </ItemGroup>

  <ItemGroup>
    <None Include="wwwroot\css\print.css" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\<Project>.BLL\<Project>.BLL.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Content Update="Views\EtatCreator\_AllEtatViews.cshtml">
      <Pack>$(IncludeRazorContentInPack)</Pack>
    </Content>
    <Content Update="Views\EtatCreator\_ComponentEtatViewPosition.cshtml">
      <Pack>$(IncludeRazorContentInPack)</Pack>
    </Content>
    <Content Update="Views\EtatCreator\_SingleEtatView.cshtml">
      <Pack>$(IncludeRazorContentInPack)</Pack>
    </Content>
  </ItemGroup>
</Project>

Any idea what might cause this issue?

fabich commented 3 years ago

I found the issue - Swashbuckle CLI had an issue with our SwaggerHostFactory after the update.

briancao commented 3 years ago

dotnet : Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Swashbuckle.AspNetCore.Swagger, Version=6.1.4.0, Culture=neutral, PublicKeyToken=62657d7474907593'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)

For anyone who ran into this recently on version 6.1.4 and .net 5, installing Swashbuckle.AspNetCore.Annotations solved my issue.

devio-at commented 2 years ago

can confirm, installing Swashbuckle.AspNetCore.Annotations also works for 6.3.0 and .net 6.

mp205 commented 1 year ago

does not seem to help for 6.5.0 and .net 7.0.202 :/

akshay-zz commented 1 year ago
  <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
    <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.4.0" />
    <PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.4.0" />

This worked for me for swashbuckle.aspnetcore.cli tool version 6.4.0. @devio-at

karygauss03 commented 1 year ago

I am facing the same problem for 6.5.0 and .NET 7.0. Any solution?

DanielSBeadle commented 1 year ago

I am also facing the same problem for 6.5.0 and .NET 7.0.

mcraiha commented 1 year ago

Check that your .csproj has 6.5.0 references if you are using dotnet tool version 6.5.0. If you have e.g. 6.4.0 reference (dotnet web api template has that version), you will get error for Swashbuckle.AspNetCore.Swagger because the .dll file is there, but it is wrong version.

I opened a ticket for better error text https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2666

JohannesNicholas commented 1 year ago

I am also facing the same problem for 6.5.0 and .NET 7.0. Any solution?

bhautikpatel1907 commented 11 months ago

I am also facing the same issue for v6.5.0 & even for v6.4.0 and net7.0 even when I haven't installed Swashbuckle.AspNetCore.SwaggerGen NuGet package. I do have installed Swashbuckle.AspNetCore, Swashbuckle.AspNetCore.Newtonsoft

Can anyone help ?

user-shashank-providence-org commented 7 months ago

Any update on this issue? I'm using .Net 8.0.100 with Swashbuckle.Aspnetcore version=6.5.0 and Cli version = 6.5.0. I installed Annotation version=6.5.0 as well still facing the same issue. I've added environment variable "DOTNET_ROLL_FORWARD=LatestMajor" also. Still no success!

oskrabanek commented 6 months ago

Problem solved by switching to a fork of this project by @Havunen https://github.com/Havunen/DotSwashbuckle/