Skip to content

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

Closed
@mitchdenny

Description

@mitchdenny

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

Metadata

Metadata

Assignees

Labels

analyzerIndicates an issue which is related to analyzer experienceold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions