Home

Overload resolution issue in LINQPad 5 (but not in VS)

I am experiencing a very strange issue with overload resolution in LINQPad 5. Consider the following code (greatly simplified to illustrate the issue):

void Main() {
    var entities = new List<Organization>();

    entities
    .WhereTest(true)
    .Count();
}

public static class IEnumerableExtensions {
    public static IEnumerable<TEntity> WhereTest<TEntity>(this IEnumerable<TEntity> query,
            bool x)
            where TEntity : IImplementationSpecific<TEntity> {
        return query;
    }

    public static IEnumerable<TEntity> WhereTest<TEntity>(this IEnumerable<TEntity> query,
            int x)
            where TEntity : IImplementationSpecific<TEntity> {
        return query;
    }
}

Issue
When I try to run this code, I get a compile error in the call to WhereTest, with the message "CS1503 Argument 2: Cannot convert from 'bool' to 'int'". If I change the parameter to int (.WhereTest(1)), the error is "CS1503 Argument 2: Cannot convert from 'int' to 'bool'". Organization definitely implements IImplementationSpecific.

Observations:

  • The is code works with no issues in Visual Studio.
  • If I delete one of the .WhereTest overloads, the code compiles and runs. What's crazy is that if I re-add the second overload after that, it all works fine.
  • If I define Organization in the same LINQPad script (as opposed to in my referenced DLL), it works with no issues.
  • If I try one of the other -- non-generic -- interfaces that Organization implements in the generic type parameter constraint in .WhereTest (e.g. IValidatableObject), I do not have this problem.

Comments

Sign In or Register to comment.