Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

DataContractSerializer does not follow .NET rules when deserializing collection data members

$
0
0

In .NET, instances of a type like the following will serialize/deserialize without a problem.

[DataContract]
public class SampleType {

  private List<String> _myStrings;
  public SampleType() {}

  [DataMember]
  public string Name { get; set; }

  [DataMember]
  public List<String> Strings {
    get {
      if (_myStrings == null) _myStrings = new List<string>();
      return _myStrings;
    }
  }
}

In Xamarin.Android, the lack of a setter on the "Strings" data member causes an InvalidOperationException: Failed to set value of type System.Collections.Generic.List'1[System.String] for property System.Collections.Generic.List'1[System.String] Strings"

According to MS documentation, .NET collections are deserialized by calling their Add method ^, and the setter is not used or required.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>