DataContractSerializer does not properly deserialize, values for methods in object are missing
- by sachin
My SomeClass
[Serializable]
[DataContract(Namespace = "")]
public class SomeClass
{
[DataMember]
public string FirstName
{
get; set;
}
[DataMember]
public string LastName
{
get; set;
}
[DataMember]
private IDictionary<long, string> customValues;
public IDictionary<long, string> CustomValues
{
get { return customValues; }
set { customValues = value; }
}
}
My XML File:
<?xml version="1.0" encoding="UTF-8"?>
<SomeClass>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
<CustomValues>
<Value1>One</Value1>
<Value2>Two</Value2>
</CustomValues >
</SomeClass>
But my problem is for the class, i am only getting some of the data for my methods when i deserialize.
var xmlRoot = XElement.Load(new StreamReader(
filterContext.HttpContext.Request.InputStream,
filterContext.HttpContext.Request.ContentEncoding));
XmlDictionaryReader reader = XmlDictionaryReader.CreateDictionaryReader(xmlRoot.CreateReader());
DataContractSerializer ser = new DataContractSerializer(typeof(SomeClass));
//Deserialize the data and read it from the instance.
SomeClass someClass = (SomeClass)ser.ReadObject(reader, true);
So when I check "someClass", FirstName will have the value john, But the LastName will be null.
Mystery is how can i get some of the data and not all of the data for the class.
So DataContractSerializer is not pulling up all the data from xml when deserializing.
Am i doing something wrong.
Any help is appreciated. Thanks in advance.
Let me know if anyone has the same problem or any one has solution