A routing conflict occurs when multiple handlers use the same HTTP method and path. Controllers and Minimal API endpoints can coexist, but they should handle different routes. section 2.4.3
Middleware ordering determines which handler receives the request first. With app.MapGet("/error", ...) before app.MapControllers(), the Minimal API handler handles the request, leaving the controller implementation effectively unused. section 2.4.3
Swagger exposes the conflict
Defining both a controller action and a Minimal API endpoint for GET /error can make Swagger UI fail with HTTP 500. The Swagger generator reports a conflicting method/path combination because OpenAPI requires each combination to be unique. Resolve the problem by deleting the redundant handler or assigning it a different route. section 2.4.3
using Microsoft.AspNetCore.Mvc;
namespace MyBGList.Controllers
{
[ApiController]
public class ErrorController : ControllerBase
{
[Route("/error")] #1
[HttpGet] #2
public IActionResult Error()
{
return Problem(); #3
}
}
}
Compare the controller-based /error handler with the Minimal API equivalent in b5 to identify duplicate routing configuration. section 2.4.3
