1.8.0 - issues with dependency on Microsoft.OpenApi version 2.0.0-preview.xx #690

Closed
opened 2025-12-29 15:30:52 +01:00 by adam · 16 comments
Owner

Originally created by @phelm1-landolakes on GitHub (Apr 30, 2025).

Originally assigned to: @StefH on GitHub.

Describe the bug

We use .Net8 because it is active LTS.

Upgrading to 1.8.0 breaks all tests that use WireMock.

 System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types.
Could not load type 'Microsoft.OpenApi.Models.OperationType' from assembly 'Microsoft.OpenApi, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042'.
Could not load type 'Microsoft.OpenApi.Models.OperationType' from assembly 'Microsoft.OpenApi, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042'.
  ----> System.TypeLoadException : Could not load type 'Microsoft.OpenApi.Models.OperationType' from assembly 'Microsoft.OpenApi, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042'.
  ----> System.TypeLoadException : Could not load type 'Microsoft.OpenApi.Models.OperationType' from assembly 'Microsoft.OpenApi, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042'.

Originally created by @phelm1-landolakes on GitHub (Apr 30, 2025). Originally assigned to: @StefH on GitHub. ### Describe the bug We use .Net8 because it is active LTS. Upgrading to 1.8.0 breaks all tests that use WireMock. ``` System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Could not load type 'Microsoft.OpenApi.Models.OperationType' from assembly 'Microsoft.OpenApi, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042'. Could not load type 'Microsoft.OpenApi.Models.OperationType' from assembly 'Microsoft.OpenApi, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042'. ----> System.TypeLoadException : Could not load type 'Microsoft.OpenApi.Models.OperationType' from assembly 'Microsoft.OpenApi, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042'. ----> System.TypeLoadException : Could not load type 'Microsoft.OpenApi.Models.OperationType' from assembly 'Microsoft.OpenApi, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042'. ```
adam added the bug label 2025-12-29 15:30:52 +01:00
adam closed this issue 2025-12-29 15:30:52 +01:00
Author
Owner

@StefH commented on GitHub (Apr 30, 2025):

@phelm1-landolakes
Can you please provide an example project to show this error?

@StefH commented on GitHub (Apr 30, 2025): @phelm1-landolakes Can you please provide an example project to show this error?
Author
Owner

@phelm1-landolakes commented on GitHub (May 1, 2025):

After further digging, this isn't your issue. It has to do with Microsoft dropping support for Swashbuckle in .Net after version 8.

https://github.com/dotnet/aspnetcore/discussions/58103

@phelm1-landolakes commented on GitHub (May 1, 2025): After further digging, this isn't your issue. It has to do with Microsoft dropping support for Swashbuckle in .Net after version 8. https://github.com/dotnet/aspnetcore/discussions/58103
Author
Owner

@tbright92 commented on GitHub (May 1, 2025):

So I just noticed the same error today when trying to update our dependencies. Even though we're on .NET 9 and I've removed all references to Swashbuckle (and Swagger) in favor of Microsoft's OpenApi and Scalar, I'm still getting the error above (with the additional error Could not load type 'Microsoft.OpenApi.Any.IOpenApiAny' from assembly 'Microsoft.OpenApi, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042'..

The only other thing I noticed is that with WireMock 1.8.0, the OpenApi transitive dependency updated from 1.6.24 to 2.0.0-preview.16

@tbright92 commented on GitHub (May 1, 2025): So I just noticed the same error today when trying to update our dependencies. Even though we're on .NET 9 and I've removed all references to Swashbuckle (and Swagger) in favor of Microsoft's OpenApi and Scalar, I'm still getting the error above (with the additional error `Could not load type 'Microsoft.OpenApi.Any.IOpenApiAny' from assembly 'Microsoft.OpenApi, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042'.`. The only other thing I noticed is that with WireMock 1.8.0, the OpenApi transitive dependency updated from 1.6.24 to 2.0.0-preview.16
Author
Owner

@StefH commented on GitHub (May 1, 2025):

@tbright92

That dependency was introduced by https://github.com/WireMock-Net/WireMock.Net/issues/1275, however I didn't know this could break?

Do you still have issues when including 2.0.0-preview.16 in your own project?

@StefH commented on GitHub (May 1, 2025): @tbright92 That dependency was introduced by https://github.com/WireMock-Net/WireMock.Net/issues/1275, however I didn't know this could break? Do you still have issues when including 2.0.0-preview.16 in your own project?
Author
Owner

@tbright92 commented on GitHub (May 1, 2025):

@StefH If I remain on WireMock 1.7.4 but update to 2.0.0-preview.16, I still have issues. Dropping down to 2.0.0-preview.15 seems to get rid of the errors phelm1-landolakes mentioned above, but I'm still seeing the IOpenApiAny error (which may be specific to .NET 9, let me test further), so it does appear to be a Microsoft issue.

@tbright92 commented on GitHub (May 1, 2025): @StefH If I remain on WireMock 1.7.4 but update to 2.0.0-preview.16, I still have issues. Dropping down to 2.0.0-preview.15 seems to get rid of the errors phelm1-landolakes mentioned above, but I'm still seeing the `IOpenApiAny` error (which may be specific to .NET 9, let me test further), so it does appear to be a Microsoft issue.
Author
Owner

@StefH commented on GitHub (May 1, 2025):

I noticed also that the '2.0.0-preview.xx' contains a lot of breaking changes.

A possible way to solve this issue is to remove the dependency on WireMock.Net.OpenApiParser (which introduced .0.0-preview.16) and change this to a more plugin-loading logic.

@StefH commented on GitHub (May 1, 2025): I noticed also that the '2.0.0-preview.xx' contains a lot of breaking changes. A possible way to solve this issue is to remove the dependency on WireMock.Net.OpenApiParser (which introduced .0.0-preview.16) and change this to a more plugin-loading logic.
Author
Owner

@StefH commented on GitHub (May 1, 2025):

@phelm1-landolakes
@tbright92

Can you please provide an example project to show this error?
I see that there's now version preview.17, probably this one has the same issue

@StefH commented on GitHub (May 1, 2025): @phelm1-landolakes @tbright92 Can you please provide an example project to show this error? I see that there's now version preview.17, probably this one has the same issue
Author
Owner

@tbright92 commented on GitHub (May 1, 2025):

I can confirm it does still exist in preview.17

@tbright92 commented on GitHub (May 1, 2025): I can confirm it does still exist in preview.17
Author
Owner

@tbright92 commented on GitHub (May 1, 2025):

To amend my previous statement, these seem to be the scenarios I've found:

Remain on WireMock 1.7.4 - all good

Remain on WireMock 1.7.4 and update to any OpenApi preview version - if using Swashbuckle, Could not load type 'Microsoft.OpenApi.Models.OperationType'. If not, Could not load type 'Microsoft.OpenApi.Any.IOpenApiAny

Update to WireMock 1.8.0 or update to WireMock.Net.OpenApiParser 1.8.0 - Could not load type 'Microsoft.OpenApi.Models.OperationType' and Could not load type 'Microsoft.OpenApi.Any.IOpenApiAny'

I also found this issue on the OpenApi.NET repo that speaks to the IOpenApiAny issue on .NET 9 specifically - https://github.com/microsoft/OpenAPI.NET/issues/2069

@tbright92 commented on GitHub (May 1, 2025): To amend my previous statement, these seem to be the scenarios I've found: Remain on WireMock 1.7.4 - all good Remain on WireMock 1.7.4 and update to _any_ OpenApi preview version - if using Swashbuckle, `Could not load type 'Microsoft.OpenApi.Models.OperationType'`. If not, `Could not load type 'Microsoft.OpenApi.Any.IOpenApiAny` Update to WireMock 1.8.0 _or_ update to WireMock.Net.OpenApiParser 1.8.0 - `Could not load type 'Microsoft.OpenApi.Models.OperationType'` _and_ `Could not load type 'Microsoft.OpenApi.Any.IOpenApiAny'` I also found this issue on the OpenApi.NET repo that speaks to the `IOpenApiAny` issue on .NET 9 specifically - https://github.com/microsoft/OpenAPI.NET/issues/2069
Author
Owner

@StefH commented on GitHub (May 1, 2025):

https://github.com/WireMock-Net/WireMock.Net/pull/1289

@StefH commented on GitHub (May 1, 2025): https://github.com/WireMock-Net/WireMock.Net/pull/1289
Author
Owner

@StefH commented on GitHub (May 2, 2025):

@tbright92 and @phelm1-landolakes

I did revert back the changes to WireMock.Net.OpenApiParser and released 1.8.1

Can you please provide me with a test project which shows this error?

@StefH commented on GitHub (May 2, 2025): @tbright92 and @phelm1-landolakes I did revert back the changes to WireMock.Net.OpenApiParser and released 1.8.1 Can you please provide me with a test project which shows this error?
Author
Owner

@phelm1-landolakes commented on GitHub (May 2, 2025):

Create directory src

In that directory create these files:

  • Example.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <LangVersion>12.0</LangVersion>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.1" />
  </ItemGroup>
</Project>
  • Program.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Example;

public class Program
{
    private static void Main(string[] args)
    {
        Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(builder => builder.UseStartup<Startup>())
        .Build()
        .Run();
    }
}

public class Startup()
{
    public void Configure(IApplicationBuilder app)
    {
        app.UseRouting();
        app.UseSwagger();
        app.UseEndpoints(endpoints => endpoints.MapControllers());
    }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllers();
        services.AddSwaggerGen();
    }
}

[Route("test")]
public class TestingController
{
    [HttpGet]
    public string Index() => "Hello";
}

Create directory test

In that directory create these files:

  • Tests.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <LangVersion>12.0</LangVersion>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
    <PackageReference Include="NUnit" Version="4.3.2" />
    <PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.15" />

    <PackageReference Include="WireMock.Net" Version="1.7.4" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\src\Example.csproj" />
  </ItemGroup>
</Project>
  • Tests.cs
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using NUnit.Framework;
using WireMock.Server;

namespace Tests;

public class Tests : WebApplicationFactory<Example.Program>
{
    protected override void ConfigureWebHost(IWebHostBuilder builder)
    {
        builder.UseStartup<Example.Startup>();
    }
    
    [Test]
    public async Task Should_return_hello()
    {
        Assert.That(await this.CreateClient().GetStringAsync("test"), Is.EqualTo("Hello"));
    }
}

Run the test

dotnet test .\test\Tests.csproj

Using 1.7.4 the test will pass.

Update the WireMock reference in the Tests.csproj to 1.8.0 and run the test again.

Test will fail with the ReflectionTypeLoadException

If you remove the injection of swashbuckle components in the Startup it will still fail.

Remove:

  • app.UseSwagger();
  • services.AddSwaggerGen();

Still fails.

But if you completely remove all references to Swashbuckle from Startup and the Example.csproj it will pass with 1.8.0
Remove:
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.1" />

Will succeed

@phelm1-landolakes commented on GitHub (May 2, 2025): ### Create directory `src` ### In that directory create these files: - **Example.csproj** ``` xml <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <LangVersion>12.0</LangVersion> <TargetFramework>net8.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.1" /> </ItemGroup> </Project> ``` - **Program.cs** ``` c# using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; namespace Example; public class Program { private static void Main(string[] args) { Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(builder => builder.UseStartup<Startup>()) .Build() .Run(); } } public class Startup() { public void Configure(IApplicationBuilder app) { app.UseRouting(); app.UseSwagger(); app.UseEndpoints(endpoints => endpoints.MapControllers()); } public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSwaggerGen(); } } [Route("test")] public class TestingController { [HttpGet] public string Index() => "Hello"; } ``` ### Create directory `test` ### In that directory create these files: - **Tests.csproj** ``` xml <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <LangVersion>12.0</LangVersion> <TargetFramework>net8.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" /> <PackageReference Include="NUnit" Version="4.3.2" /> <PackageReference Include="NUnit3TestAdapter" Version="5.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.15" /> <PackageReference Include="WireMock.Net" Version="1.7.4" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\src\Example.csproj" /> </ItemGroup> </Project> ``` - **Tests.cs** ``` c# using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; using NUnit.Framework; using WireMock.Server; namespace Tests; public class Tests : WebApplicationFactory<Example.Program> { protected override void ConfigureWebHost(IWebHostBuilder builder) { builder.UseStartup<Example.Startup>(); } [Test] public async Task Should_return_hello() { Assert.That(await this.CreateClient().GetStringAsync("test"), Is.EqualTo("Hello")); } } ``` ### Run the test ### `dotnet test .\test\Tests.csproj` Using 1.7.4 the test will pass. Update the WireMock reference in the Tests.csproj to 1.8.0 and run the test again. Test will fail with the `ReflectionTypeLoadException` If you remove the injection of swashbuckle components in the Startup it will still fail. **Remove:** - `app.UseSwagger();` - `services.AddSwaggerGen();` Still fails. But if you completely remove all references to Swashbuckle from Startup and the Example.csproj it will pass with 1.8.0 **Remove:** `<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.1" />` Will succeed
Author
Owner

@tbright92 commented on GitHub (May 2, 2025):

I can confirm that 1.8.1 fixes the error when using .NET 9 and either OpenApi/Scalar or Swashbuckle/Swagger. Thanks so much @StefH for the quick turnaround!

@tbright92 commented on GitHub (May 2, 2025): I can confirm that 1.8.1 fixes the error when using .NET 9 and either OpenApi/Scalar or Swashbuckle/Swagger. Thanks so much @StefH for the quick turnaround!
Author
Owner

@phelm1-landolakes commented on GitHub (May 2, 2025):

Same. 1.8.1 fixes the issue.

@phelm1-landolakes commented on GitHub (May 2, 2025): Same. 1.8.1 fixes the issue.
Author
Owner

@StefH commented on GitHub (May 2, 2025):

Now I've to start thinking on how to fix https://github.com/WireMock-Net/WireMock.Net/issues/1275 . . . .

@StefH commented on GitHub (May 2, 2025): Now I've to start thinking on how to fix https://github.com/WireMock-Net/WireMock.Net/issues/1275 . . . .
Author
Owner

@StefH commented on GitHub (May 2, 2025):

@tbright92 / @phelm1-landolakes

The solution to be able to use the 2.0.0-preview.xx version from OpenApi is to use ILRepack to make the all OpenApi types internal which should solve the issue.

@StefH commented on GitHub (May 2, 2025): @tbright92 / @phelm1-landolakes The solution to be able to use the 2.0.0-preview.xx version from OpenApi is to use **ILRepack** to make the all OpenApi types _internal_ which should solve the issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#690