Skip to content

AmbiguousMatchException thrown when using required route constraint #62278

Open
@DavidVollmers

Description

@DavidVollmers

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have two routes similar routes where I use route constraints to evade ambiguity:

Route 1:

[HttpGet]
[Route("test/{name}")]
public IActionResult TestByName(string name) { return Ok(); }

Route 2 (with guid):

[HttpGet]
[Route("test/{id:guid}")]
public IActionResult TestById(Guid id) { return Ok(); }

This works as expected. If I now add the required route constraint (see documentation) to both routes it will throw a Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException:

Route 1:

[HttpGet]
[Route("test/{name:required}")]
public IActionResult TestByName(string name) { return Ok(); }

Route 2 (with guid):

[HttpGet]
[Route("test/{id:guid:required}")]
public IActionResult TestById(Guid id) { return Ok(); }

Expected Behavior

It should not throw a Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException.

Steps To Reproduce

See above.

Exceptions (if any)

Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException

.NET Version

8.0.410

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions