Route parameter and argument optionality do not match (ASP0007)
Key dotnet.api.route-optionality-mismatch · Severity warning · Category api
ASP.NET Core analyzer ASP0007. Flags a route parameter declared optional ({id?}) whose handler argument is not nullable, or the reverse. The route matches requests the handler cannot bind.
Incorrect
Section titled “Incorrect”app.MapGet("/orders/{page?}", (int page) => List(page));Correct
Section titled “Correct”app.MapGet("/orders/{page?}", (int? page) => List(page ?? 1));