Skip to content

NullReferenceException in ApiVersionParameterDescriptionContext.RemoveAllParametersExcept #250

Closed
@dbrink

Description

@dbrink

When using the ApiExplorer in AspNet Core a null reference exception is thrown if the API defines a parameter as part of a route, but does not have matching parameter on the controller method.

[HttpGet("foo/{unmatched}"]
public string GetFoo()
{
   return "foo";
}

With no matching C# parameter on GetFoo() the ApiParameterDescription's ModelMetadata is null. A null coalescing operator should fix the problem.

void RemoveAllParametersExcept( ApiParameterDescription parameter )
{
// code omitted
   if ( otherParameter?.ModelMetadata.DataTypeName == nameof( ApiVersion ) )
   {
      collection.Remove( otherParameter );
   }
// code omitted
}

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions