Bug 8428 - Linker needs to preserve IntentService default constructor
Summary: Linker needs to preserve IntentService default constructor
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 4.5.x
Hardware: PC Mac OS
: High normal
Target Milestone: ---
Assignee: Alex Rønne Petersen
Depends on:
Reported: 2012-11-15 12:02 UTC by Jonathan Pryor
Modified: 2013-07-11 11:43 UTC (History)
3 users (show)

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

Scratch.MyIntentService.zip (10.29 KB, application/zip)
2012-11-15 12:02 UTC, Jonathan Pryor

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 Jonathan Pryor 2012-11-15 12:02:30 UTC
Created attachment 2946 [details]

The IntentService default constructor must be preserved if [IntentService] is preserved.

To reproduce:

1. Build attached project:

    $ unzip Scratch.MyIntentService.zip
    $ cd Scratch.MyIntentService.zip
    $ xbuild /t:SignAndroidPackage /p:Configuration=Release *.csproj

Key part of the project (for expository purposes):

	class MyIntentService : IntentService {
		public MyIntentService ()
			: base ("value")

		protected override void OnHandleIntent (Intent intent)
			Console.WriteLine ("MyIntentService.OnHandleIntent:");

2. View the build output:

    $ open obj/Release/android/src/scratch/myintentservice/MyIntentService.java

Actual behavior:

The Android Callable Wrapper for MyIntentService doesn't contain a default constructor.

Expected behavior:

The Android Callable Wrapper for MyIntentService _should_ contain a default constructor.

Additional information:

This happens because the linker removes the IntentService default constructor before the ACW is generated, because MyIntentService doesn't use the IntentService default constructor, but instead the IntentService(string) constructor.
Comment 1 Jonathan Pryor 2012-11-15 12:17:53 UTC
Since this is a linker bug, if we invoke the IntentService default constructor the linker will preserve it, so a workaround would be to add the following constructor to MyIntentService:

	private MyIntentService(string whatevs)
		: base ()

`whatevs` can be of any type; the primary purpose is the `: base()`, which will preserve the IntentService default constructor.
Comment 2 Alex Rønne Petersen 2013-06-04 17:57:30 UTC
The parameterless ctor now has a [Preserve(Conditional = true)] attribute in master.
Comment 3 Peter Collins 2013-06-12 02:03:46 UTC
After following the steps listed above, the class MyIntentService.java contains two constructors, shown in this gist:

jonp: Does the preceding output for MyIntentService.java verify this bug as fixed?

Built against:
Windows 7x64
X.A. 4.7.9 - 47cd3984
Comment 4 Jonathan Pryor 2013-06-12 10:43:13 UTC
@PeterC: Yes, the output verifies the bug as fixed, as it contains a default constructor.