Bug 38807 - NPE in null-conditional extension method
Summary: NPE in null-conditional extension method
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2016-02-16 16:39 UTC by Nuno Cruces
Modified: 2016-02-16 20:04 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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.

Related Links:
Status:
RESOLVED FIXED

Description Nuno Cruces 2016-02-16 16:39:18 UTC
This code throws an NPE (in the extension method) when compiled with Xamarin and run on the iOS Simulator. It works when built with Visual Studio and the Xamarin Mac Agent.


using System;

public static class Extensions
{
    public static void Invoke(this EventHandler handler, object sender)
    {
        handler(sender, EventArgs.Empty);
    }
}

// elsewhere...
EventHandler evt = null;
evt.Invoke(sender);


I use the null conditional operator elsewhere, so that's not the problem. It seems specific to extension methods.

This stackoverflow discussion seems relevant:
http://stackoverflow.com/questions/24148313/null-propagation-operator-and-extension-methods


System data:

Xamarin Studio
Version 5.10.2 (build 56)
Installation UUID: 6d20facb-a8ce-46a1-a05a-9ae135bafd13
Runtime:
	Mono 4.2.2 (explicit/996df3c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402020030

Xamarin.Profiler
Not Installed

Xamarin.Android
Version: 6.0.1.10 (Business Edition)
Android SDK: /Users/Nuno/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 24.4
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 21.1.2

Java SDK: /usr
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

Xamarin Android Player
Not Installed

Apple Developer Tools
Xcode 7.2.1 (9548.1)
Build 7C1002

Xamarin.iOS
Version: 9.4.1.25 (Business Edition)
Hash: 962a050
Branch: master
Build date: 2016-01-29 16:59:11-0500

Xamarin.Mac
Not Installed

Build Information
Release ID: 510020056
Git revision: bb74ff467c62ded42b7b7ac7fdd2edc60f8647b0
Build date: 2016-01-26 16:24:41-05
Xamarin addins: 8b797d7ba24d5abab226c2cf9fda77f666263f1b
Build lane: monodevelop-lion-cycle6-c6sr1

Operating System
Mac OS X 10.11.1
Darwin Nuno-Crucess-MacBook-Air.local 15.0.0 Darwin Kernel Version 15.0.0
    Sat Sep 19 15:53:46 PDT 2015
    root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64
Comment 1 Marek Safar 2016-02-16 20:04:52 UTC
Already fixed in Mono 4.3