Skip to content

Overload resolution fails in complex scenario with Delegate overloads and extension methods #55691

@davidfowl

Description

@davidfowl

Version Used:
Version 17.0.0 Preview 4.0 [31616.459.main]

Steps to Reproduce:

var app = new WebApp();

app.Map("/sub", builder =>
{
    builder.UseAuth();
});


class WebApp : IAppBuilder, IRouteBuilder
{
    public void UseAuth()
    {
        
    }
}

public interface IAppBuilder
{
    void UseAuth();
}

public interface IRouteBuilder
{

}

static class AppBuilderExtensions
{
    public static IAppBuilder Map(this IAppBuilder app, PathSring path, Action<IAppBuilder> callback) => app;
}

public static class RouteBuilderExtensions
{
    public static IRouteBuilder Map(this IRouteBuilder routes, string path, Delegate callback) => routes;
}

struct PathSring
{
    public PathSring(string? path)
    {
        Path = path;
    }

    public string? Path { get; }

    public static implicit operator PathSring(string? s) => new PathSring(s);

    public static implicit operator string?(PathSring path) => path.Path;
}

Expected Behavior:

AppBuilderExtensions.Map would be chosen by the overload resolution algorithm.

Actual Behavior:

The call is ambiguous between the following methods or properties: 'AppBuilderExtensions.Map(IAppBuilder, PathSring, Action)' and 'RouteBuilderExtensions.Map(IRouteBuilder, string, Delegate)' C:\Users\david\source\repos\ConsoleApp133\WebApplication1\Program.cs

It seems like the implicit conversion on PathString throws off the overload resolution completely. If PathString is replaced with string, it works as expected.

cc @cston

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions