Skip to content

WebApi with ApiVersioning on dotNet Core fails to get param from body #452

Closed
@softvision-andreirobu

Description

@softvision-andreirobu

I have a dotNet Core server which is a middleware between mobile applications and a third party server. This server is used just to add an SSL certificate and make requests, rather installing certificates on every single device.

I've created some controllers and the endpoints have a signature similar to this:
public async Task VerifyOrder([FromBody] object request,....)

This worked perfectly fine until I decided to add API Versioning. In order to accomplish this, I've added in Startup.cs the following code block in the ConfigureServices method:

services.AddApiVersioning(o =>
{
o.AssumeDefaultVersionWhenUnspecified = true;
o.DefaultApiVersion = new ApiVersion(1, 0);
o.ApiVersionReader = new MediaTypeApiVersionReader();
o.ApiVersionSelector = new CurrentImplementationApiVersionSelector(o);
o.ReportApiVersions = true;
});

After this modification, when making requests instead of getting the body as an object, I'm getting the version which is set at the controller level.

As a workaround, I changed the type of request param to be JObject but, I think it should work with an object as well.

Thanks,
Andrei Robu

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions