Bug 22313 - [Export] doesn't support generic type parameters
Summary: [Export] doesn't support generic type parameters
Status: CONFIRMED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 4.16.0
Hardware: PC Mac OS
: High normal
Target Milestone: master
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-08-22 15:14 UTC by Jonathan Pryor
Modified: 2014-11-21 12:49 UTC (History)
2 users (show)

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


Attachments
Scratch.ExportCollections.zip (12.18 KB, application/zip)
2014-08-22 15:14 UTC, Jonathan Pryor
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 for Bug 22313 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Jonathan Pryor 2014-08-22 15:14:50 UTC
Created attachment 7775 [details]
Scratch.ExportCollections.zip

The [Export] custom attribute doesn't support generic types on parameters or return types.
Comment 1 Jonathan Pryor 2014-08-22 15:18:28 UTC
Repro:

1. Download Attachment #7775 [details].
2. Extract:

    unzip Scratch.ExportCollections.zip

3. Build:

    cd Scratch.ExportCollections/Scratch.ExportCollections
    xbuild

Expected results: it builds (maybe?)

Actual results:

> error XA4209: Failed to create JavaTypeInfo for class: Scratch.ExportCollections.MyPreferences due to System.NullReferenceException: Object reference not set to an instance of an object
>   at Xamarin.Android.Tasks.JavaTypeInfo+Signature..ctor (System.String name, System.String signature, System.String connector, System.String managedParameters, System.String outerType, System.String superCall)
>   at Xamarin.Android.Tasks.JavaTypeInfo+Signature..ctor (Mono.Cecil.MethodDefinition method, Java.Interop.ExportAttribute export)
>   at Xamarin.Android.Tasks.JavaTypeInfo.AddMethod (Mono.Cecil.MethodDefinition registeredMethod, Mono.Cecil.MethodDefinition implementedMethod)
>   at Xamarin.Android.Tasks.JavaTypeInfo..ctor (Mono.Cecil.TypeDefinition type, System.String outerType, System.Object log)
>   at Xamarin.Android.Tasks.JavaTypeInfo..ctor (Mono.Cecil.TypeDefinition type, System.Object log)
>   at Xamarin.Android.Tasks.Generator.GenerateJavaSource (Microsoft.Build.Utilities.TaskLoggingHelper log, Mono.Cecil.TypeDefinition t, System.String outputPath, Boolean useSharedRuntime, Boolean hasExportReference)

The cause for the exception is this method:

>	[Java.Interop.Export ("getStringSet")]
>	public System.Collections.Generic.ICollection<string> GetStringSet (string key, System.Collections.Generic.ICollection<string> defValues)
>	{
>		return base.GetStringSet (key, defValues);
>	}

The ACW generator can't create a JNI name for e.g. `ICollection<string>`, returns null, and things fail from there.
Comment 2 Jonathan Pryor 2014-08-22 15:24:51 UTC
The reason for wanting this method is to work around a different bug/issue

http://forums.xamarin.com/discussion/22790/binding-library-with-override-of-sharedpreferences-and-problems-with-java-util-set

What's happening in the above is that they're binding a Java library ("oak") which provides a custom android.content.SharedPreferences subclass, but the .jar is build against API-10. As such, the custom type is "missing" the SharedPreferences.getStringSet() method (added in API-11), and the binding project + Application are setting $(TargetFrameworkVersion) to v4.0 (API-14).

Getting the binding project building is easy enough -- add a partial class which implements ISharedPreferences.GetStringSet().

Things fall to pieces when you try to SUBCLASS the SharedPreferences type, because the bound type doesn't provide SharedPreferences.getStringSet(), and the android.jar that javac is using has SharedPreferences.getStringSet(), so javac requires that the (non-abstract) "C#" subclass have that method, which doesn't exist.

The obvious answer: Add the "missing" GetStringSet() method, and [Export] it.

Unfortunately that fails (Comment #1).

The "correct" workaround is to provide the [Register] attribute on the binding's implementation of GetStringSet(), and then override GetStringSet() in the C# subclass so that the ACW declares getStringSet().
Comment 3 Rajneesh Kumar 2014-10-30 06:04:35 UTC
I have checked this issue and able to reproduce this issue. To reproduce this issue I have followed the steps provided in bug description.

Steps I followed:

1. Open attached sample application in XS
2. Build the application
3. On building, you will get following building error.

Error : https://gist.github.com/Rajneesh360Logica/5e468e6761a4a9eb540d

Build Output: https://gist.github.com/Rajneesh360Logica/2d754f41b238d07541eb

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

Environment Info:

=== Xamarin Studio ===

Version 5.5.3 (build 6)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 3.10.0 ((detached/e204655)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000023

=== Xamarin.Android ===

Version: 4.18.0 (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		4.5    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 6.0.1 (6528)
Build 6A317

=== Xamarin.iOS ===

Version: 8.4.0.15 (Business Edition)
Hash: 08968c4
Branch: 
Build date: 2014-10-20 21:48:06-0400

=== Xamarin.Mac ===

Version: 1.10.0.18 (Business Edition)

=== Build Information ===

Release ID: 505030006
Git revision: fbe3e9453daf6a3bb9a9709ed22bec35f7c9056b
Build date: 2014-10-23 13:08:38-04
Xamarin addins: e44add2b39de4dd57c0742bb2e620dfad84c64c6

=== Operating System ===

Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64