Skip to content

ArgumentNullException in ApplyContentTypeVersionActionFilter.ApplyApiVersionMediaTypeParameter(…) #528

Closed
@roxiemobile

Description

@roxiemobile

ApplyContentTypeVersionActionFilter throws an exception, if ApiVersioningOptions.ApiVersionReader property initialized with ApiVersionReader.Combine(…) method:

System.ArgumentNullException: Value cannot be null.
Parameter name: text
   at Microsoft.Extensions.Primitives.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at Microsoft.Extensions.Primitives.StringSegment.Equals(String text, StringComparison comparisonType)
   at Microsoft.AspNetCore.Mvc.Versioning.ApplyContentTypeVersionActionFilter.ApplyApiVersionMediaTypeParameter(Object state) in C:\BA\6915\s\src\Microsoft.AspNetCore.Mvc.Versioning\Versioning\ApplyContentTypeVersionActionFilter.cs:line 56
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.FireOnStartingMayAwait(Stack`1 onStarting)

Example of configuring API Versioning Options in our application:

public void ConfigureServices(IServiceCollection services) {
    …
    services.AddApiVersioning(
        options => {

            options.AssumeDefaultVersionWhenUnspecified = false;
            options.DefaultApiVersion = new ApiVersion(10, 0);
            options.ErrorResponses = new VendorErrorResponseProvider();

            options.ApiVersionReader = ApiVersionReader.Combine(
                new VendorMediaTypeApiVersionReader(new List<string> {"version", "v"}, options.DefaultApiVersion),
                new UrlSegmentApiVersionReader()
            );
        });
    …
}

Application starts crashing after migration from Microsoft.AspNetCore.Mvc.Versioning version 3.1.2 to >= 3.1.3. I'm investigate the problem and found that main reason of this crash is here: DescriptionContext.AddParameter(…)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions