Skip to content

Incompatibility with Swashbuckle.AspNetCore v10.x due to hardcoded CLI version 9.0.4 #158

@g-jonpouliot

Description

Describe the bug

After upgrading Swashbuckle.AspNetCore from version 9.0.6 to 10.0.1 (which includes Microsoft.OpenApi v2.3.0), the Workleap.OpenApi.MSBuild package (v0.12.3) fails to generate OpenAPI specifications during the build process.

The build completes successfully for the main projects, but the OpenAPI spec generation step fails with a TypeLoadException when trying to load Microsoft.OpenApi.Models.OpenApiDocument from the Microsoft.OpenApi assembly.

To Reproduce

Steps to reproduce the behavior:

  1. Update Swashbuckle.AspNetCore package reference from version 9.0.6 to 10.0.1 in a project that uses Workleap.OpenApi.MSBuild (v0.12.3)
  2. Run dotnet build on the solution
  3. Observe the OpenAPI spec generation failure in the build output

Expected behavior

The OpenAPI specification should be generated successfully during the build process, as it did with Swashbuckle.AspNetCore v9.0.6.

Error Output

Workleap.OpenApi.MSBuild.targets(75,5): Warning  : Unhandled exception. System.TypeLoadException: Could not load type 'Microsoft.OpenApi.Models.OpenApiDocument' from assembly 'Microsoft.OpenApi, Version=2.3.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042'.
   at Swashbuckle.AspNetCore.Cli.Program.<>c.<Main>b__1_5(IDictionary`2 namedArgs)
   at Swashbuckle.AspNetCore.Cli.Program.<>c.<Main>b__1_5(IDictionary`2 namedArgs)
   at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args) in /_/src/Swashbuckle.AspNetCore.Cli/CommandRunner.cs:line 56
   at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args) in /_/src/Swashbuckle.AspNetCore.Cli/CommandRunner.cs:line 47
   at Swashbuckle.AspNetCore.Cli.Program.Main(String[] args) in /_/src/Swashbuckle.AspNetCore.Cli/Program.cs:line 199

Workleap.OpenApi.MSBuild.targets(75,5): Warning  : OpenAPI spec generation failed for C:\Sources\workleap-ai-connectors\connectors\api\src\Workleap.Ai.Connectors.WebApi\bin\Debug\net10.0\openapi\openapi-v1.yaml. Retrying again...

Workleap.OpenApi.MSBuild.targets(75,5): Warning  : An error occurred while validating the OpenAPI specification: OpenApi file for C:\Sources\workleap-ai-connectors\connectors\api\src\Workleap.Ai.Connectors.WebApi\bin\Debug\net10.0\openapi\openapi-v1.yaml could not be generated.

Environment (please complete the following information):

  • OS: Windows 11
  • .NET SDK: 10.0.100
  • Target Framework: net10.0
  • Swashbuckle.AspNetCore: 10.0.1 (upgraded from 9.0.6)
  • Microsoft.OpenApi: 2.3.0 (transitive dependency from Swashbuckle v10)
  • Workleap.OpenApi.MSBuild: 0.12.3
  • IDE: Visual Studio / Rider

Additional context

The root cause is that Swashbuckle.AspNetCore v10.0.1 upgraded its dependency on Microsoft.OpenApi from v1.x to v2.3.0, which introduced breaking changes in the API. The Microsoft.OpenApi.Models namespace and types like OpenApiDocument have been restructured in v2.x.

The Workleap.OpenApi.MSBuild package (v0.12.3) uses Swashbuckle.AspNetCore.Cli internally to generate OpenAPI specs, but this CLI tool is not compatible with the new Microsoft.OpenApi v2.x API surface.

The issue is in the SwaggerManager.cs file where the Swashbuckle CLI version is hardcoded:

private const string SwaggerVersion = "9.0.4";

Source: SwaggerManager.cs:L7

This hardcoded version installs Swashbuckle.AspNetCore.Cli v9.0.4, which depends on Microsoft.OpenApi v1.x. When the consuming application uses Swashbuckle.AspNetCore v10.x (with Microsoft.OpenApi v2.x), there's a version mismatch between:

  1. The CLI tool (v9.0.4) expecting Microsoft.OpenApi v1.x types
  2. The application assembly (built with v10.x) containing Microsoft.OpenApi v2.x types

This causes the TypeLoadException when the CLI tool tries to load types from the incompatible Microsoft.OpenApi v2.x assembly.

Related Links:

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions