1

I'm trying to implement api versioning following this tutorial. So in my startup I have:

var constraintResolver = new DefaultInlineConstraintResolver()
{
    ConstraintMap =
    {
        ["apiVersion"] = typeof( ApiVersionRouteConstraint )
    }
};

configuration.MapHttpAttributeRoutes(constraintResolver);
configuration.AddApiVersioning()

and my controllers:

[Route("api/v{version:apiVersion}/my")]
[ApiVersion("1.0")]
[ApiVersion("2.0")]
public class MyV1Controller 

[Route("api/v{version:apiVersion}/my")]
[ApiVersion("3.0")]
public class MyV3Controller 

When I request for http://localhost/api/v1.0/my I get an error

Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL.\r\n\r\nThe request has found the following matching controller types: \r\nMyV1Controller\r\nMyV2Controller

Could you please advice how to make controller versioning to work?

3
  • Your "V1" controller can have multiple versions? Would the V1 controller be one version? ...Why two attributes? Commented Sep 28, 2017 at 12:56
  • This may be an issue with dot in your url. Commented Sep 28, 2017 at 13:40
  • My api consist of few controllers. While there was a version 2 that affected other conrollers there were no changes made to MyV1Controller. So I just increased the number. Commented Sep 28, 2017 at 13:40

1 Answer 1

1

I took a break and I remembered that in my project I have a custom IHttpControllerSelector implementation which extends DefaultHttpControllerSelector.

configuration.Services.Replace(typeof(IHttpControllerSelector), new ApiControllerSelector(config));

After I removed it versioning started to work. Executing configuration.AddApiVersioning sets ApiVersionControllerSelector in ServicesContainer. It was accidently replaced with my custom implementation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.