EndpointName metadata not set automatically

Behavior that was introduced in .NET 6 RC 1 to automatically set IEndpointNameMetadata for endpoints has been reverted. IEndpointNameMetadata is no longer set automatically to avoid issues with duplicate endpoint names.

Version introduced

ASP.NET Core 6 RC 2

Previous behavior

In ASP.NET Core 6 RC 1, IEndpointNameMetadata was automatically set for endpoints that referenced a method group. For example, the following code produced an endpoint for /foo with EndpointName set to GetFoo.

app.MapGet("/foo", GetFoo);

New behavior

Starting in ASP.NET Core 6 RC 2, IEndpointNameMetadata is not automatically set. The following code does not generate any IEndpointNameMetadata.

app.MapGet("/foo", GetFoo);

Type of breaking change

This change can affect source compatibility.

Reason for change

The behavior of automatically setting endpoint name metadata was not robust and resulted in issues where the same name was set for different endpoints. For more information, see dotnet/aspnetcore#36487.

We recommend that you manually set IEndpointNameMetadata using the WithName extension method to set the metadata.

app.MapGet("/foo", GetFoo).WithName("GetFoo");

Affected APIs

N/A