dotnet / dotnet/aspnetcore

add an analyzer to catch parameter name mismatches between route and [FromRoute] params

Open
#37,987 1 comment 0 reactions 0 assignees View on GitHub
analyzer area-minimal area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

VS 2022 Preview 5, .net 6 preview rc2

Currently AFAICT a simple typo in a parameter name isn't caught by any analyzer - I changed these two lines from the default asp.net core web api proj but got no warning of the FromRoute param not being defined in the route (someParam), nor the Route attribute route having an unused param (somePram)

```csharp
[HttpGet, Route("/foo/{somePram}")]
public IEnumerable Get([FromRoute] string someParam)
```

The somewhat good news is that you at least get a runtime failure with the required someParam not being bound thanks to nullable reference types and all, but it would be great to have something to catch this at design time if possible. The swagger surfacing both versions of the param helps the developer notice the mismatch as well.

![image](https://user-images.githubusercontent.com/82121503/139688179-47e1679f-a9be-4068-b6cd-7a2a14815903.png)

There may be web api use cases that prevent this from being something that can be enabled by default, but as we've had developers hit it multiple times, we wanted to at least ask.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.