Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app.MapControllers() => ReflectionTypeLoadException. Could not load type 'Microsoft.OpenApi.Any.IOpenApiAny' from assembly 'Microsoft.OpenApi #2069

Open
bartvanhoey opened this issue Jan 17, 2025 · 1 comment

Comments

@bartvanhoey
Copy link

In the Program.cs file of a .Net 9 Core API project the line app.MapControllers throws an ReflectionTypeLoadException.
This happens as of version Microsoft.OpenApi 2.0.0-preview1. Microsoft.OpenApi 1.6.23 does NOT throw an Exception.

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'Microsoft.OpenApi.Any.IOpenApiAny' from assembly 'Microsoft.OpenApi, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042'.
at System.Reflection.RuntimeModule.GetDefinedTypes()
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider.PopulateFeature(IEnumerable1 parts, ControllerFeature feature) at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature) at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetControllerTypes() at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors() at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context) at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection() at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize() at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.GetChangeToken() at Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration1..ctor(Func1 changeTokenProducer, Action1 changeTokenConsumer, TState state)
at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.Subscribe()
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.GetOrCreateDataSource(IEndpointRouteBuilder endpoints)
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllers(IEndpointRouteBuilder endpoints)
at Program.

$(String[] args) in C:\Data\MyGitHubRepos\Net9Authentication\Net9Auth.API\Program.cs:line 76
System.TypeLoadException: Could not load type 'Microsoft.OpenApi.Any.IOpenApiAny' from assembly 'Microsoft.OpenApi, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042'.

@bartvanhoey bartvanhoey changed the title app.MapControllers => ReflectionTypeLoadException. Could not load type 'Microsoft.OpenApi.Any.IOpenApiAny' from assembly 'Microsoft.OpenApi app.MapControllers() => ReflectionTypeLoadException. Could not load type 'Microsoft.OpenApi.Any.IOpenApiAny' from assembly 'Microsoft.OpenApi Jan 17, 2025
@MaggieKimani1
Copy link
Contributor

@bartvanhoey this error is as a result of a breaking change we've introduced in v2.0 of the lib.
We've gotten rid of the IOpenApiAny type and replaced it with JsonNode to model examples and extensions for compatibility with JSON schema types.

Here's a link to the release notes that can help you fix the breaking change: https://github.com/microsoft/OpenAPI.NET/releases/tag/2.0.0-preview1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants