Skip to content

NullReferenceException in TryMatchModelVersion with OData + OpenAPI and only the default version #850

Closed
@icnocop

Description

@icnocop

Hi.

When I try to get swagger.json for an OData API which exposes only the default version, the following exception occurs:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Asp.Versioning.ApiExplorer.ODataApiDescriptionProvider.TryMatchModelVersion(ApiDescription description, IReadOnlyList`1 items, IODataRoutingMetadata& metadata) in E:\github\icnocop\aspnet-api-versioning-preview3-fixes\src\AspNetCore\OData\src\Asp.Versioning.OData.ApiExplorer\ApiExplorer\ODataApiDescriptionProvider.cs:line 198
   at Asp.Versioning.ApiExplorer.ODataApiDescriptionProvider.OnProvidersExecuted(ApiDescriptionProviderContext context) in E:\github\icnocop\aspnet-api-versioning-preview3-fixes\src\AspNetCore\OData\src\Asp.Versioning.OData.ApiExplorer\ApiExplorer\ODataApiDescriptionProvider.cs:line 120
   at Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.GetCollection(ActionDescriptorCollection actionDescriptors)
   at Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.get_ApiDescriptionGroups()
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I will create a PR with a sample project that can reproduce the issue.

I'm using the latest code from the dev/css/preview3-fixes branch with an ASP.NET Core web application targeting .NET Core 3.1.

It seems to be different than #837

Thank you.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions