Bug 32663 - Calls to MessagingCentre.Subscribe fail if made in a polymorphic way
Summary: Calls to MessagingCentre.Subscribe fail if made in a polymorphic way
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 8.4.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-07-31 09:58 UTC by adunn
Modified: 2017-07-25 12:53 UTC (History)
4 users (show)

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


Attachments
Project to illustrate problem (8.50 KB, application/zip)
2015-08-03 05:36 UTC, adunn
Details
Log files when application runs and fails on a real device (9.31 KB, application/zip)
2015-08-05 08:44 UTC, adunn
Details


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 Developer Community or GitHub 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 NOT_REPRODUCIBLE

Description adunn 2015-07-31 09:58:26 UTC

    
Comment 1 adunn 2015-07-31 10:05:47 UTC
This problem might be a specific instance of something more general, but the following code illustrates the issue.

If this code is ran as is, the callback is never made, but if the commented out code that subscribes via the static call directly is made it works.

This problem does not occur when the same code is run on Android.

Curiously if the TArgs argument is a string it always works, but if it is an int or enum or other object it fails.

public class MessageTest
{
	private const string MessageKey = "MessageKey";
	private interface SubscriberInterface
	{
		void Subscribe<TSender, TArgs> (object subscriber, string message, Action<TSender, TArgs> callback, TSender source = null) where TSender : class;
	}

	private class SubscriberImplmentation : SubscriberInterface
	{
		public void Subscribe<TSender, TArgs> (object subscriber, string message, Action<TSender, TArgs> callback, TSender source = null) where TSender : class
		{
			Xamarin.Forms.MessagingCenter.Subscribe<TSender, TArgs>(subscriber,message,callback,source);
		}			
	}

	public void Test ()
	{
		SubscriberInterface subscriber = new SubscriberImplmentation ();
		ConsoleColor color = ConsoleColor.Black;

		// The direct call to MessagingCenter sets up the sibscriber and a call back is received
		/*Xamarin.Forms.MessagingCenter.Subscribe<object,ConsoleColor> (this, MessageKey, 
		(sender, argument) => System.Diagnostics.Debug.WriteLine ("["+argument+"]" + " was sent to me"));*/

		// If the direct call to MessagingCenter is not made, the indirect call does not result in a callback, if both are called it does.
		subscriber.Subscribe<object,ConsoleColor> (this, MessageKey, 
		(sender, argument) => System.Diagnostics.Debug.WriteLine ("["+argument+"]" + " was sent to me"));

	        System.Diagnostics.Debug.WriteLine ("Sending Message");
		Xamarin.Forms.MessagingCenter.Send<object,ConsoleColor> (this, MessageKey, color);
     }
}
Comment 2 Zoltan Varga 2015-07-31 13:04:54 UTC
Could you attach a complete test case ? Also, what xamarin.ios version are you using ?
Comment 3 adunn 2015-08-03 05:36:46 UTC
Created attachment 12334 [details]
Project to illustrate problem
Comment 4 adunn 2015-08-03 05:37:43 UTC
Xamarin.iOS
Version: 8.10.3.2 (Business Edition)
Hash: 8b265d6
Branch: master
Build date: 2015-06-30 15:19:13-0400
Comment 5 Arpit Jha 2015-08-05 03:50:36 UTC
I have checked this issue and observed that when I run the project with Indirect call and (Direct call + Indirect call ) in both case app not deployed on simulator.

However when I implement the same in android it works.

Screencast: http://www.screencast.com/t/ETJkEkZ9R

Please let me know if I missed anything to reproduce this issue.


Environment Info:
=== Xamarin Studio ===

Version 5.9.4 (build 5)
Installation UUID: 3d25a767-a003-4a7d-9f5e-e57987cf6cf0
Runtime:
	Mono 4.0.2 ((detached/c99aa0c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400020005

=== Xamarin.Android ===

Version: 5.1.4.16 (Enterprise Edition)
Android SDK: /Users/mac360_xamarin/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 6.3 (7569)
Build 6D570

=== Xamarin.iOS ===

Version: 8.10.3.2 (Enterprise Edition)
Hash: 8b265d6
Branch: master
Build date: 2015-06-30 15:19:13-0400

=== Xamarin.Mac ===

Version: 2.0.2.35 (Enterprise Edition)

=== Build Information ===

Release ID: 509040005
Git revision: 8010a90f6e246b32364e3fb46ef2c9d1be9c9a2b
Build date: 2015-06-08 16:52:06-04
Xamarin addins: 7e93e9c3503f28770f23ce1b7eafd829919f18e8

=== Operating System ===

Mac OS X 10.10.4
Darwin mac360-xamarins-Mac-mini.local 14.4.0 Darwin Kernel Version 14.4.0
    Thu May 28 11:35:04 PDT 2015
    root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64
Comment 6 adunn 2015-08-05 04:08:11 UTC
Sorry I neglected to say that this problem occurs on iOS devices not simulators.
If I run this on an iPad 2 running 8.3 I see the problem, on a simulator it calls back as expected.
Comment 7 Arpit Jha 2015-08-05 05:47:48 UTC
I have checked this issue again and observed the same behaviour as simulator.

Could you please provide us reproduction steps, iOS Device logs and IDE logs.So that we can reproduce at our end.

iOS Device Logs: XS ->View ->Pads->iOS Device Logs.

IDE logs: XS ->Help ->Open Log Directory.
Comment 8 adunn 2015-08-05 08:44:16 UTC
Created attachment 12363 [details]
Log files when application runs and fails on a real device

The iOS device log is from a run that fails, the video shows the application succeeding  on a simulator and then failing on a real device.

http://www.screencast.com/t/hAyNnN3LVY
http://www.screencast.com/t/pIVA0AFTNuz
Comment 9 John Miller [MSFT] 2017-07-25 12:53:39 UTC
Thanks so much for taking the time to submit this report! I attempted to reproduce this issue based on the bug description with the latest Xamarin.iOS 10.12.0.14, and I was unable to hit the problem. If this issue is still occurring for you, please reopen this report and attach a project that reproduces the issue, ideally starting with a new template project and then adding just the code necessary to demonstrate the issue.