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
It could be a glitch in an older Roslyn implementation. Have you tried it in LINQPad 7?
The problem does not occur in LINQPad 7, but I cannot upgrade to that, because it does not support EF 6 as far as I know. Are there any plans to support EF 6? MS supports it in .Net Core, 5 and 6.
There's a third-party EF 6 driver for LINQPad 6 and 7:
https://github.com/Peter-B-/Ef6.Core.LINQPadDriver
Thank you. I will look into this.