Bug 47738 - Nested IList<T> marshaling is incorrect
Summary: Nested IList<T> marshaling is incorrect
Status: CONFIRMED
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 5.1
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2016-11-23 15:37 UTC by Jonathan Pryor
Modified: 2017-07-13 19:45 UTC (History)
5 users (show)

Tags:
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 for Bug 47738 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 2016-11-23 15:37:13 UTC
TODO: MOAR INPUT. This is a sketch of the problem.

Consider the following Java method declaration:

> public void setData(Map<String, List<String>> data) {...}

Currently, this is bound as:

> public virtual void SetData(IDictionary<string, IList<string>> data) {...}

Which is nominally fine.

The problem is that the marshaling may not be "sufficiently deep"; consider this invocation:

    var data = new Dictionary<string, IList<string>> {
      { "key", new List<string> {
        "value1",
        "value2",
      } },
    };
    instance.SetData(data);

The above currently fails with a ClassCastException:

> java.lang.ClassCastException: mono.android.runtime.JavaObject cannot be cast to java.util.List
>   at com.example.mylibrary.SomeClass.setData()
>   ...
Comment 2 Atsushi Eno 2017-01-05 08:37:32 UTC
IMO - we should not change the current behavior.

Changing this to examine every entry in the list will harm performance. And this behavior has long been there and any developers who needed deep marshaling should have already done with custom conversion otherwise it would have never worked.

What we should do instead is 1) give a bold warning "DON'T DO THIS" and 2) offer a utility extension method that make it to make every collection entry safe, recursively.
Comment 3 Cody Beyer (MSFT) 2017-07-13 19:45:24 UTC
Are we wanting to go through with a new warning? Leaving this as confirmed for now.