Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 15059 [details]
Code for reproduction
It seems extension methods with the same name as a non-extension methods are problematic
for null propagation in Mono.
In the below code, IDictionary has a method named TryGetValue, and I add +1 extension method
with the same name. Null propagation won't work, the method will be called also
with null dictionary.
If running the code below in Xamarin Studio on a Mac, the extension method will be called.
If running it in Visual Studion on a Windows, it won't be called.
public static class MyHelpers
public static TValue TryGetValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue = default(TValue))
return dictionary.TryGetValue(key, out value) ? value : defaultValue;
static class MyMainClass
static void Main(string args)
Dictionary<string, string> dictionary = null;
var aa = dictionary?.TryGetValue("dfg"); // TryGetValue will be called!
Created attachment 15060 [details]
Versio info provided by Xamarin Studio
Already fixed in Mono 4.3
If it helps others in the future. I also ran into this issue with the following code:
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
if (source == null) throw new ArgumentNullException(nameof(source));
object foo = null;
foo?.ForEach(x => x.GetHashCode());
A notable difference is the method naming conflict is with the static ForEach method on System.Array rather than an instance method.
Upgrading from Mono 4.2.3 to Mono 4.4.0 does indeed resolve the problem.
Renaming the extension method also works.