v2
v3
AOT
Error
xUnit1065
"MemberData method is ambiguous"
Cause
A violation of this rule occurs when [MemberData] points at an ambiguous member.
Reason for rule
In reflection mode, ambiguous methods cannot be resolved at runtime.
In Native AOT mode, overloaded methods cannot be resolved at build time.
How to fix violations
To fix a violation of this rule:
- In both modes, removing the additional overloads or renaming them will resolve the issue.
- In reflection mode, you may additionally attempt to change the parameters to resolve the ambiguity.
Examples
Violates
using Xunit;
public class xUnit1065
{
public static TheoryData<int> DataSource() => DataSource(1);
public static TheoryData<int> DataSource(int multiplier) => [42 * multiplier];
[Theory]
[MemberData(nameof(DataSource))]
[MemberData(nameof(DataSource), 4)]
public void TestMethod(int _)
{ }
}
Does not violate
using Xunit;
public class xUnit1065
{
public static TheoryData<int> DataSource(int multiplier = 1) => [42 * multiplier];
[Theory]
[MemberData(nameof(DataSource))]
[MemberData(nameof(DataSource), 4)]
public void TestMethod(int _)
{ }
}