I'm trying make a program to read a simple xml file into my class. I've been using this previous question as a guide: How to Deserialize XML document
The code runs fine with no exceptions, but for some reason, SCArray.ShortCut = null and count is 0. I'm having trouble debugging this because there are no exceptions.
Is there a way to catch this error (i.e., why it's not reading the xml correctly, or what part of my code is causing it to return null results from reading the xml)?
<?xml version="1.0"?>
<ShortCutsArray>
<Shortcut>
<Name>Item1</Name>
<Path>http://www.example1.com</Path>
</Shortcut>
<Shortcut>
<Name>Item2</Name>
<Path>\\Server\example2\ex2.exe</Path>
</Shortcut>
</ShortCutsArray>
The c# code:
class Program
{
public static void Main(string[] args)
{
string shortcuts_file = @"\\server\ShortcutLocation.xml";
ShortCutsArray SCArray = null;
XmlSerializer serializer = new XmlSerializer(typeof(ShortCutsArray));
StreamReader reader = new StreamReader(shortcuts_file);
SCArray = (ShortCutsArray)serializer.Deserialize(reader);
reader.Close();
}
}
[Serializable()]
[System.Xml.Serialization.XmlRoot("ShortCutsArray")]
public class ShortCutsArray
{
[XmlArray("ShortCutsArray")]
[XmlArrayItem("ShotCut", typeof(ShortCut))]
public ShortCut[] ShortCuts { get; set; }
}
[Serializable()]
public class ShortCut
{
[System.Xml.Serialization.XmlElement("Name")]
public string Name { get; set; }
[System.Xml.Serialization.XmlElement("Path")]
public string Path { get; set; }
}