I try to deserialize object and get System.NullReferenceException. I can't find where exception is fired and what is the cause of exception.
I try to deserialize like this:
public static List<T> Get<T>()
{
string path = GetFilePath (typeof(T));
List<T> list;
using (StreamReader stream = new StreamReader (path))
{
XmlSerializer serializer = new XmlSerializer (typeof(List<T>));
list = (List<T>)serializer.Deserialize (stream);
}
return list;
}
StackTrace
at System.Xml.Serialization.XmlSerializationReader.OnUnknownNode (System.Xml.XmlNode node, System.Object o, System.String qnames) [0x00000] in :0 at System.Xml.Serialization.XmlSerializationReader.UnknownNode (System.Object o, System.String qnames) [0x00000] in :0 at System.Xml.Serialization.XmlSerializationReader.UnknownNode (System.Object o) [0x00000] in :0 at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadListElement (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, System.Object list, Boolean canCreateInstance) [0x00000] in :0 at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadObject (System.Xml.Serialization.XmlTypeMapping typeMap, Boolean isNullable, Boolean checkType) [0x00000] in :0 at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadRoot (System.Xml.Serialization.XmlTypeMapping rootMap) [0x00000] in :0 at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadRoot () [0x00000] in :0 at System.Xml.Serialization.XmlSerializer.Deserialize (System.Xml.Serialization.XmlSerializationReader reader) [0x00000] in :0
GetFilePathreturn? What's in the file?GetFilePathitself is doing the right thing? Have you debugged through to check that?