Skip to content

[MethodDataSource] Arguments that fit two overloads equally: source-gen picks the first, reflection throws AmbiguousMatchException, no analyzer diagnostic #7175

Closed

Description

@thomhurst

Found while extending the [MethodDataSource] overload parity table in #7143.

What happens

When the Arguments of a [MethodDataSource] fit two overloads equally well, and neither overload's parameter types are more specific than the other's, the two modes behave differently, and the analyzer reports nothing:

public static IEnumerable<(string, string)> Tie(string expected, IComparable value) { yield return (expected, "IComparable"); }
public static IEnumerable<(string, string)> Tie(string expected, IConvertible value) { yield return (expected, "IConvertible"); }

[Test]
[MethodDataSource(nameof(Tie), Arguments = new object[] { "IComparable", 1 })]
public async Task Test(string expected, string chosen) => await Assert.That(chosen).IsEqualTo(expected);
  • Build: no TUnit0001 (or any other) diagnostic.
  • Source-generated mode: passes. The generator keeps the first declared overload (Tie(string, IComparable)).
  • Reflection mode (--reflection): fails with AmbiguousMatchException: Ambiguous match found for '... Tie(System.String, System.IComparable)', from the binder in MethodDataSourceAttribute.ResolveDataSourceMethod.

The source-generated behaviour is the same on main, which always called the first member with the name.

Expected

Both modes should behave the same. The simplest fix is probably an analyzer error for Arguments that fit more than one overload equally well, the same way C# reports CS0121 for an ambiguous call. Then neither mode reaches the runtime difference.

Activity

  1. added a commit that references this issue on Oct 20, 2026
    69f0597
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions