I have a problem with deserialization in my silverlight project. I have class Obj with this methods and variables.
public class Obj
{
private string _name;
private Uri _iconUri;
private string _stringUri;
private List<ObjItem> _items = new List<ObjItem>();
public List<ObjItem> Items
{
get { return _items; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public Uri IconUri
{
get
{
return _iconUri;
}
}
public string StringUri { get { return _stringUri; } }
public int Count
{
get { return _items.Count; }
}
public Obj(string name,string uriString = null)
{
_name = name;
if (uriString == null)
{
_iconUri = null;
}
else
{
_iconUri = new Uri(uriString, UriKind.Relative);
}
_stringUri = uriString;
}
// for deserialization
public Obj()
{
}
}
Before serialization all fields are not empty!
After deserialization all fields are not empry except _iconUri and _stringUri fields.
Why is it happened?
I’ll be waiting for your replies.
Thank you!
Those two don’t have setters. Silverlight has a restricted security model, where you cant can’t cheat by accessing private fields; only public members can be accessed. So: add public setters to those properties if you want them to work with most serializers on SL.
To be specific: _name is being set by the Name setter, and _items is being set in the constructor via the field-initializer.