Skip to content

Set Endpoint names automatically for minimal #37089

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

Open
dodyg opened this issue Sep 29, 2021 · 2 comments
Open

Set Endpoint names automatically for minimal #37089

dodyg opened this issue Sep 29, 2021 · 2 comments
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-routing
Milestone

Comments

@dodyg
Copy link

dodyg commented Sep 29, 2021

Describe the bug

The usage of LinkGenerator.GetPathByName will throw exception if there are route handlers from method of the same name but from different scope.

If you don't use LinkGenerator.GetPathByName on GreetingPage inferred route name, it works fine.

To Reproduce

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;

static IResult Index(LinkGenerator linker) => 
    Results.Text(@$"<html><body>
    <ul>
        <li><a href=""{linker.GetPathByName("AboutPage", values: null)}"">About</a></li>
        <li><a href=""{linker.GetPathByName("AboutPage", values: new { name = "anne"})}"">About Anne</a></li>
        <li><a href=""{linker.GetPathByName("AboutPage", values: new { name = "babka"})}"">About Babka</a></li>
        <li><a href=""{linker.GetPathByName("GreetingPage", values: new { name = "babka"})}"">Greet Babka</a></li>
    </ul>
    </body></html>" , "text/html");

static IResult AboutPage(string? name) => Results.Text(@$"<html><body><h1>About {name}</h1></body></html>"  , "text/html");
static IResult GreetingPage(string? name) => Results.Text(@$"<html><body><h1>Hi {name}</h1></body></html>"  , "text/html");

var app = WebApplication.Create();

app.Map("/", Index);
app.Map("/about", AboutPage);
app.Map("/greet", GreetingPage);
app.Map("/greet2", Pages.GreetingPage);
app.Run();

   
public static class Pages 
{
    public static IResult GreetingPage(string? name) => Results.Text(@$"<html><body><h1>Hi {name}</h1></body></html>"  , "text/html");
}

Full code is here https://github.com/dodyg/practical-aspnetcore/tree/net5.0/projects/net6/link-generator-path-by-route-name-inferred-duplicated

Exceptions (if any)

 System.InvalidOperationException: The following endpoints with a duplicate endpoint name were found.

      Endpoints with endpoint name 'GreetingPage':
      /greet => GreetingPage
      /greet2 => GreetingPage

Further technical details

.NET SDK (reflecting any global.json):
 Version:   6.0.100-rc.1.21463.6
 Commit:    e627d556a1

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19043
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\

Host (useful for support):
  Version: 6.0.0-rc.1.21451.13
  Commit:  d7619cd4b1

.NET SDKs installed:
  3.1.302 [C:\Program Files\dotnet\sdk]
  3.1.413 [C:\Program Files\dotnet\sdk]
  5.0.100 [C:\Program Files\dotnet\sdk]
  5.0.401 [C:\Program Files\dotnet\sdk]
  6.0.100-rc.1.21458.32 [C:\Program Files\dotnet\sdk]
  6.0.100-rc.1.21463.6 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.1.21452.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.1.21451.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0-rc.1.21451.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
@dodyg dodyg changed the title LinkGeneator.GetPathByName throws exception on inferred route name because method of the same name but different scope LinkGenerator.GetPathByName throws exception on inferred route name because method of the same name but different scope Sep 29, 2021
@javiercn javiercn added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-routing old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Sep 29, 2021
@BrennanConroy
Copy link
Member

We reverted the behavior in RC2, #36518 so the name is no longer inferred.

Triage: We want to fix this in .NET 7 (add back inferred names), using this issue to track that.

@BrennanConroy BrennanConroy changed the title LinkGenerator.GetPathByName throws exception on inferred route name because method of the same name but different scope Set Endpoint names automatically for minimal Sep 30, 2021
@BrennanConroy BrennanConroy added this to the .NET 7 Planning milestone Sep 30, 2021
@ghost
Copy link

ghost commented Oct 11, 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.

@captainsafia captainsafia added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels labels Jun 14, 2023
@captainsafia captainsafia modified the milestones: .NET 8 Planning, Backlog Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-routing
Projects
No open projects
Status: No status
Development

No branches or pull requests

5 participants