Bug 25808

Summary: DataContractJsonSerializer cannot deserialize array to IEnumerable<T>
Product: Android Reporter: Morten Nielsen <mnielsen>
Component: BCL Class LibrariesAssignee: marcos.henrich
Status: VERIFIED FIXED    
Severity: normal CC: joao.matos, kumpera, mnielsen, mono-bugs+monodroid, peter.collins, ramc, vargaz
Priority: ---    
Version: 5.1   
Target Milestone: 5.1   
Hardware: PC   
OS: Windows   
Tags: Is this bug a regression?: ---
Last known good build:

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.