Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASP.NET Core: No route matches the supplied values. #131

Closed
alexander-frolov opened this issue May 23, 2017 · 13 comments
Closed

ASP.NET Core: No route matches the supplied values. #131

alexander-frolov opened this issue May 23, 2017 · 13 comments

Comments

@alexander-frolov
Copy link

It appears that the issue reported in #18 returned in Microsoft.AspNetCore.Mvc.Versioning v1.1.0-rc1.

When I use query string versioning and have code like this

[ApiVersion("1.0")]
[Route("[controller]")]
public class TestController : Controller
{
        [HttpPost]
        [Consumes("application/json")]
        [Produces("application/json")]
        public async Task<IActionResult> RegisterAsync([FromBody] [Required] AgentInfo agentInfo)
        {
            return CreatedAtAction(
                "GetAgentInfoAsync",
                new
                {
                    agentSerialNumber = agentInfo.SerialNumber,
                    apiVersion = HttpContext.GetRequestedApiVersion().ToString()
                },
                await _agentRepository.CreateAsync(agentInfo.SerialNumber, agentInfo));
        }
}

When I request the RegisterAsync the first time, it fails with a "No route matches the supplied values" error. All subsequent requests are successful.

I tried with v1.1.0-beta2 and there is no such a problem.

@commonsensesoftware
Copy link
Collaborator

Yeah ... some internal mechanics changed and apparently I didn't have acceptance coverage for some of these edge cases. I'm almost certain that this is related to #133.

Weird that this would only fail on the first call. I know that is the result of an internal optimization. Your controller is very simple though. I'm surprised by this particular scenario. Do you have multiple API versions defined for this route or other routes with similar form? I want in corporate these findings into the acceptance tests.

@alexander-frolov
Copy link
Author

I have only one API version (1.0) but there are two controllers using the same routing scheme inside the project. There are multiple middlewares involved on other levels. There is Swagger. There is authentication middleware. And there is exception filter also. The code above is simplified a bit too. For instance, I did not include the GetAgentInfoAsync action but it is there actually.

@commonsensesoftware
Copy link
Collaborator

Since you said this worked in Beta 2, this must be the regression I'm tracking in #133. I'm close to having a solution. I'd like to incorporate as many of the regression cases into the acceptance test suite as possible so this doesn't happen again. As soon as it's ready, I'll notify folks to try it out. Thanks for your patience.

commonsensesoftware pushed a commit that referenced this issue May 25, 2017
@commonsensesoftware
Copy link
Collaborator

RC2 has been officially published. Let me know if you run into any other issues.

@alexander-frolov
Copy link
Author

Hi Chris,

Unfortunately, the issue is still there. I've just reproduced it in the simple controller.

    [ApiVersion("1.0")]
    [Route("api/[controller]")]
    public class ValuesController : Controller
    {
        [HttpPost]
        [Consumes("application/json")]
        public IActionResult Post([FromBody] string value)
        {
            return CreatedAtAction("Get",
                new
                {
                    id = "12345678",
                    apiVersion = HttpContext.GetRequestedApiVersion().ToString()
                }, value);
        }

        [HttpGet("{id}", Name = "Get")]
        [Produces("application/json")]
        public IActionResult Get([FromRoute] [Required] string id)
        {
            return Ok(new
            {
                value = "Test"
            });
        }
    }

The issue occurs only with the CreatedAtAction method. If I switch to CreatedAtRoute, it works with no problems.

@commonsensesoftware
Copy link
Collaborator

What's the response you get? Can you share your Startup.cs configuration too? If you have a complete repro, feel free to attach it.

@alexander-frolov
Copy link
Author

I get status code 500 caused by the following exception:

System.InvalidOperationException: No route matches the supplied values.
   at Microsoft.AspNetCore.Mvc.CreatedAtActionResult.OnFormatting(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ObjectResultExecutor.ExecuteAsync(ActionContext context, ObjectResult result)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeResultAsync>d__30.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResultFilterAsync>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResultExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.<Invoke>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()

The test solution is attached.
VersioningTest.zip

@commonsensesoftware
Copy link
Collaborator

commonsensesoftware commented May 31, 2017

Great! Thanks. I think this might be related to the issue in #130 too. I have it fixed in a PR, but not merged yet. I'll check this repro against it. Hopefully, it will be same issue. I was wanted to published RC3. I'll let you know what I find. Probably tomorrow.

@commonsensesoftware
Copy link
Collaborator

I was able to run your repro against the forthcoming RC3 build and it seemed to work just fine. I should have the release out within the hour and then you give the latest package a try.

@commonsensesoftware
Copy link
Collaborator

RC3 is out. Give it a whirl and let me know.

@commonsensesoftware
Copy link
Collaborator

Were you able to give RC3 a try? Did it fix this issue? Thanks.

@alexander-frolov
Copy link
Author

Yup. Just checked it with RC3. The issue is fixed now. Thank you very much!

@commonsensesoftware
Copy link
Collaborator

Awesome! I've very close to finally shipping v1.1 and I want to make sure these last few critical issues have been resolved. Thanks again for confirming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants