Bug 25808 - DataContractJsonSerializer cannot deserialize array to IEnumerable<T>
Summary: DataContractJsonSerializer cannot deserialize array to IEnumerable<T>
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries (show other bugs)
Version: 5.1
Hardware: PC Windows
: --- normal
Target Milestone: 5.1
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2015-01-07 19:12 UTC by Morten Nielsen
Modified: 2015-05-07 09:54 UTC (History)
7 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 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:
VERIFIED FIXED

Description Morten Nielsen 2015-01-07 19:12:01 UTC
The following class cannot be deserialized:
        [DataContract]
        public class TestContract
        {
            [DataMember]
            public IEnumerable<string> items { get; set; }
        }
I'm using the following code:

   string json = "{\"items\":[\"item1\",\"item2\"]}";
   using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
   {
       DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(TestContract));
       var result = (TestContract)jsonSerializer.ReadObject(stream);
   }

If I change the data member to be string[] it works. Note that the IEnumerable<string> works in .NET 4.5 (Desktop,store,phone).
Comment 1 Rodrigo Kumpera 2015-01-16 12:13:18 UTC
Hi Marcos,

Can you work on this over the next couple of weeks?
Comment 2 Zoltan Varga 2015-01-16 14:12:16 UTC
Fixed in mono master ba6d6d74cdaa50d60b28b1ea3c5617e277dae714.
Comment 3 Ram Chandra 2015-05-07 09:54:12 UTC
I have checked this issue on both OS X and windows with following builds and I am able to reproduce this issue.

OS X Environment Info:
OS X: 10.10.3
Mono: 4.0.1.28
XA: 4.20.2.1
XS:  5.9.1 (build 2)
>Screencast: http://www.screencast.com/t/yeQwkznFjb

Windows Environment Info:
Windows 8.1
XVS:  3.9.236.0
XS: 5.9.1.2
VS: 2013
>Screencast: http://www.screencast.com/t/VZ3QlHaywujt

To verify this issue I have checked this issue with following builds:

OS X Environment Info:
OS X: 10.10.3
Mono: 4.0.1.28
XA: 5.1.1.1
XS:  5.9.1 (build 2)
Screencast: http://www.screencast.com/t/WZLph5ZaCvJ

Windows Environment Info: 
Windows 8.1
XVS:  3.11.538
XS: 5.9.1.2
VS: 2013
Screencast: http://www.screencast.com/t/dLrZoTTPG

Now, DataContractJsonSerializer able to deserialize array to IEnumerable<T>.

This issue has been fixed. Hence I am closing this issue.