Bug 14493 - Unregister Action<object> throws an NRE in but not in
Summary: Unregister Action<object> throws an NRE in but not in
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: unspecified
Hardware: Macintosh All
: --- major
Target Milestone: ---
Assignee: Bugzilla
: 14552 ()
Depends on:
Reported: 2013-09-06 15:13 UTC by Alexandre Pepin
Modified: 2013-09-09 11:16 UTC (History)
8 users (show)

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:

Description Alexandre Pepin 2013-09-06 15:13:52 UTC
Unregistering an Action<object> throws a "System.NullReferenceException: Object reference not set to an instance of an object". Sample :

Action<object> a = null;
a += Demo.Update;
a -= Demo.Update; // Crash here
public void Update(object o){ }

But, unregistering an Action (no parameters) or an Action<int> doesn't crash. It only crash when using an object as parameter. It was working on Xamarin.iOS
Comment 1 Sebastien Pouliot 2013-09-08 10:26:57 UTC
Confirmed. The NRE still happens when using the JIT (simulator) on the most recent monotouch (which is based on the mono 3.2.3 candidate hash revision).

* it does not happen when the AOT compiler is used (i.e. works on device);
* it might explain a few recent bug reports where NRE occurs (only on 6.4.4, not 6.4.3)
Comment 2 Zoltan Varga 2013-09-09 05:42:00 UTC
I can't reproduce this, can somebody attach a complete test project ?
Comment 3 Sebastien Pouliot 2013-09-09 08:06:12 UTC
That's what I added to an existing unit test app to duplicate the issue. NRE happens when executing the last line (using simulator, fine on device).

+		public class Demo_14493 {
+			public void Update (object o)
+			{
+			}
+		}
+		[Test]
+		public void Action_14493 ()
+		{
+			var Demo = new Demo_14493 ();
+			Action<object> a = null;
+			a += Demo.Update;
+			a -= Demo.Update; // Crash here
+		}
Comment 4 Sebastien Pouliot 2013-09-09 08:41:40 UTC
A similar case was reported on the forum (with test case)

Comment 5 Sebastien Pouliot 2013-09-09 09:18:39 UTC
Just like #14552 this works fine in Simulator/Release (JIT) but fails under Debug (JIT)
Comment 6 Zoltan Varga 2013-09-09 09:49:08 UTC
I can reproduce this now, it only happens while debugging.
Comment 7 Sebastien Pouliot 2013-09-09 09:51:31 UTC
hmm... at least that explains why automated testing on the bots did not catch this condition.
Comment 8 Zoltan Varga 2013-09-09 11:16:16 UTC
Fixed in mono master a918a647712b08f02ad5957a6d9019ee0030ea44.
Comment 9 Zoltan Varga 2013-09-09 11:16:38 UTC
*** Bug 14552 has been marked as a duplicate of this bug. ***