Bug 16800 - Rx Observable.FromEventPattern doesn't work in Release mode on Android 4.3
Summary: Rx Observable.FromEventPattern doesn't work in Release mode on Android 4.3
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.10.1
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2013-12-14 10:26 UTC by Jakub Arnold
Modified: 2013-12-16 03:30 UTC (History)
1 user (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 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:

Description Jakub Arnold 2013-12-14 10:26:59 UTC
I have a simple activity with a TextView. The following code
    Observable.FromEventPattern<TextChangedEventArgs>(textbox, "TextChanged");

works just fine in Debug configuration, but if I switch to release it fails with

    [mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: Could not find event 'TextChanged' on object of type 'Android.Widget.TextView'.
Comment 1 Atsushi Eno 2013-12-14 23:33:59 UTC
Because you have to specify linking description.

Observable.FromEventPattern() specifies event by name, thus gets the member using reflection, which doesn't count the member to preserve.
Comment 2 Jakub Arnold 2013-12-15 04:26:43 UTC
If I understand this correctly the linker will strip away the `TextChanged` event from the textbox, because I'm not referencing it directly.

But I'm not sure how to use the [Preserve] annotation for a builtin type such as TextView. It seems that the only way to make this work is by fake-assigning an event handler (as the guide suggests).

	var ignore = false;
	if (ignore)
		searchBox.TextChanged += (sender, e)

Isn't there a more clean way to do this? If I omit the `ignore` var the compiler complains with unreachable code warning, and I can't really make an empty lambda expression without { }
Comment 3 Atsushi Eno 2013-12-16 03:30:05 UTC
[Preserve] is not applicable if you don't own the sources of the library. TextView is in Mono.Android.dll and you don't build it, so this attribute is not for you.

With Custom Linking with LinkDescription xml, you don't have to make your code dirty.