Skip to content

Route parameter TryParse checks does not handle handler parameters with [FromRoute] attribute where name is provided. #45581

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

Closed
1 task done
mitchdenny opened this issue Dec 13, 2022 · 1 comment · Fixed by #45597
Assignees
Labels
analyzer Indicates an issue which is related to analyzer experience old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Comments

@mitchdenny
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Given the following example:

using Microsoft.AspNetCore.Mvc;
using System.Diagnostics.CodeAnalysis;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/{blah}", ([FromRoute(Name = "blah")]MyRouteObject x) => "Hello World!");

app.Run();

public class MyRouteObject
{
}

... the recently added Roslyn analyzer fails to warn that MyRouteObject does not have a TryParse(...) method. This results in a runtime error when this code is run.

Expected Behavior

We should raise an analyzer warning on the handler parameter because it's a route parameter that does not implement TryParse.

Steps To Reproduce

See above.

Exceptions (if any)

At runtime we get the following exception:

InvalidOperationException: No public static bool MyRouteObject.TryParse(string, out MyRouteObject) method found for x.

.NET Version

8.0.100-alpha.1.22613.3

Anything else?

No response

@mitchdenny mitchdenny self-assigned this Dec 13, 2022
@javiercn javiercn added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Dec 14, 2022
@captainsafia captainsafia added the analyzer Indicates an issue which is related to analyzer experience label Dec 15, 2022
@captainsafia captainsafia added this to the .NET 8 Planning milestone Dec 15, 2022
@ghost
Copy link

ghost commented Dec 15, 2022

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
analyzer Indicates an issue which is related to analyzer experience old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants