I have two extension methods defined in a C# class. When I compile code that uses these extension methods in Visual Studio 2015, they compile correctly. When I run the same code on an on-premises Team Foundation Build Server, using MSBuild 2015 with /p:VisualStudioVersion=14.0, the code will not compile. What additional steps to do I need to take to configure the build server so that the code will compile?
These are the relevant method signatures
public static IEnumerable<TResult> LeftOuterJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector) where TInner : class;
public static IEnumerable<TResult> LeftOuterJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector) where TInner : class
This is the compile error on the build server:
I have two extension methods defined in a C# class. When I compile code that uses these extension methods in Visual Studio 2015, they compile correctly. When I run the same code on an on-premises Team Foundation Build Server, using MSBuild 2015 with /p:VisualStudioVersion=14.0, the code will not compile. What additional steps to do I need to take to configure the build server so that the code will compile?
These are the relevant method signatures
public static IEnumerable<TResult> LeftOuterJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector)
where TInner : class;
public static IEnumerable<TResult> LeftOuterJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner?, TResult> resultSelector)
where TInner : struct;
Based on the compiler error in the build server, it appears that the build process is accepting the "where TInner : struct" version of the method as a suitable overload even though TInner is a reference type, whereas Visual Studio on my development machine does not consider these methods ambiguous. This is the compile error on the build server:
The call is ambiguous between the following methods or properties:
'Extensions.LeftOuterJoin<AnonymousType#1,ReferenceType,AnonymousType#2,AnonymousType#3>(System.Collections.Generic.IEnumerable<AnonymousType#1>, System.Collections.Generic.IEnumerable<ReferenceType>, System.Func<AnonymousType#1,AnonymousType#2>, System.Func<ReferenceType,AnonymousType#2>, System.Func<AnonymousType#1,ReferenceType,AnonymousType#3>)'
and
'Extensions.LeftOuterJoin<AnonymousType#1,ReferenceType,AnonymousType#2,AnonymousType#4>(System.Collections.Generic.IEnumerable<AnonymousType#1>, System.Collections.Generic.IEnumerable<ReferenceType>, System.Func<AnonymousType#1,AnonymousType#2>, System.Func<ReferenceType,AnonymousType#2>, System.Func<AnonymousType#1,ReferenceType?,AnonymousType#4>)'