Xamarin Archive step does not support C# 6 overload resolution

My team’s Bitrise build is failing after I made changes to our Xamarin codebase that leverage the updated overload resolution in C# 6 (described here: https://stackoverflow.com/a/37746488). Specifically, I added extension-method overloads that differ based on the type of callback parameter they accept: one takes an Action, while another takes a Func<Task>, like so:

public static void OnClick(this View view, object host, Action eventHandler)
public static void OnClick(this View view, object host, Func<Task> eventHandler)

Thanks to the improved overload resolution in C# 6, I should not need to give these methods different names, as the compiler will determine the appropriate overload to use based on the type of the provided callback argument.

However, while these changes compile successfully in Xamarin Studio 6.1.5 w/ Mono 4.8.1 as well as Rider EAP 22, they cause CS0121 errors in Bitrise’s Xamarin Archive step similar to the following:

error CS0121: The call is ambiguous between the following methods or properties: 'OnClick(View, object, Action)' and 'OnClick(View, object, Func<Task>)'

The only solution thus far has been to rename one of the overloads, but I would like to avoid this if possible.

Environment

Stack: Xamarin Stable with XCode 8, on macOS 10.12 (Sierra)

The issue occurs in the Xamarin Archive step, v1.4.2, using either xbuild or msbuild.

Reproducibility

  • Does a “Rebuild” help? NO
  • Does upgrading the build Step to the latest version help? NO

Build log

(Sent via email)

Hi @ethan.romba,

Thanks for reporting this here!

Did you try to build this project on your Mac using the latest Xamarin Studio?

Can you please follow this guide How to debug your build locally / "It works on my Mac/PC but not on bitrise.io" and let us know how it goes?

Also, did you try it with Mono 5? The latest Xamarin Studio now comes with Mono 5 by default, and so that’s the default on our Xamarin Stable stack too (we use the standard installation of Xamarin Studio without any customization).

I finally got the chance to try building my project with the latest version of Visual Studio for Mac (7.0.1 w/ Mono 5.0.1.1) as well as Visual Studio 2017 on a PC, and both IDEs report the same errors that I see from Bitrise.

After a bit more research, I believe my predicament boils down to two separate issues:

In the end, it sounds like I’ll have to wait for a future version of C# (and Roslyn / Mono) before I can leverage the simpler syntax I was trying to use, but at least Bitrise is working as expected in the meantime. Thanks for your help!

1 Like

Wow, good catch @ethan.romba and thanks for sharing it here! Was quite interesting to read (for me at least :smiley:) and definitely something what can help others too :wink: