I've noticed odd compiler specific enforcement of overload resolution after pulling in the code on a Xamarin project that was being developed exclusively on OSX with Xamarin Studio into a Win 10 box running Visual Studio 2015.2. My curiosity eventually lead me to this post which had the benefit of the attentions of Jon Skeet and Eric Lippert, and was really informative on the subject.

That said, I wanted to play around to see what a minimum replication story would be for this difference between the two compilers, and what I've managed to do is create the following two snippets.

I'll start this off with the Roslyn success case: ​

using System; public static class Program { public static void Main() { Foo(Bar); } // Outputs Func public static void Bar(string input) { Console.WriteLine(input); } public static string Bar() { return string.Empty; } public static void Foo(Action<string> input) { input("Action"); } public static void Foo(Func<string> input) { Console.WriteLine("Func"); } }

And the case in which Mono will work:

using System; public static class Program { public static void Main() { Foo(Bar); } public static void Bar() { Console.WriteLine("Action"); } public static void Foo(Action input) { input(); } public static void Foo(Func<string> input) { Console.WriteLine("Func"); } }

Final recap on compiler versions used:

Roslyn: 1.2.0.60425

v12: 12.0.31010.0

mono: 4.2.3.0

So I'm out of my depth at this point, and my understanding is that the specification is a bit murky about this particular part of how things are handled. Having code that is specific to a compiler to be valid is obviously not the best, so I may just need to request that team members either provide a lambda expression to avoid ambiguity over Method Groups, or at the least an explicit cast.

The Roslyn case is especially odd to me, as it seems that it's decision is the most arbitrary of the selections. Any additional insight would be greatly appreciated.

Edit:

I did manage to find an additional snippet that will successfully compile on both Mono and Roslyn but fail on the v12 compiler: