MarxWright
MarxWright

Reputation: 317

Ambiguous call between within Mono for System.Linq.Enumerable.Max

When using a lambda expression to find the maximum Key value from the following code I get the following compile error when compiling on a Unix system using gmcs:

List<KeyValuePair<int, RunnerBase>> lsFinishOrder = new List<KeyValuePair<int, RunnerBase>>();

...fill out List...

iMaxPlace = lsFinishOrder.Max(p => p.Key);

The code compiles fine on a Windows machine and performs as expected when executed the issue only arises when I try to compile it on Linux.

error CS0121: The call is ambiguous between the following methods or properties: `System.Linq.Enumerable.Max<System.Collections.Generic.KeyValuePair<int,Pathfinder.RunnerBase>>(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<int,Pathfinder.RunnerBase>>, System.Func<System.Collections.Generic.KeyValuePair<int,Pathfinder.RunnerBase>, long >)'

and `System.Linq.Enumerable.Max<System.Collections.Generic.KeyValuePair<int,Pathfinder.RunnerBase>>(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<int,Pathfinder.RunnerBase>>, System.Func<System.Collections.Generic.KeyValuePair<int,Pathfinder.RunnerBase>, int >)'

/usr/lib/mono/gac/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll (Location of the symbol related to previous error)

Any ideas would be welcome as I've tried a lot of different approaches and I'm wondering if I'm not looking in the wrong places. I'm targeting .Net 3.5 on my windows build.

Upvotes: 3

Views: 392

Answers (1)

Jeppe Stig Nielsen
Jeppe Stig Nielsen

Reputation: 61982

This looks like a bug in Mono's compiler.

Try this to help it:

iMaxPlace = lsFinishOrder.Max((Func<KeyValuePair<int, RunnerBase>, int>)(p => p.Key));

Upvotes: 2

Related Questions