I'm using XmlSerializer to serialize and deserialize an XML Document.
public class FolderPath
{
public string Path { get; set; }
}
This is how I am Serializing the class:
private static void UpdateFolderPathsXml(List<FolderPath> folderPaths,
string fileName = "FolderPaths.xml")
{
XmlSerializer x = new XmlSerializer(folderPaths.GetType());
TextWriter writeFileStream = new StreamWriter(fileName);
x.Serialize(writeFileStream, folderPaths);
writeFileStream.Close();
}
This is how I Deserialize, and also where I get the error, Outer Exception is
There is an error in XML document (2, 2)
, and inner exception is
ArrayOfFolderPath xmlns='' was not expected.
XmlSerializer x = new XmlSerializer(typeof (FolderPath));
using (FileStream reader = new FileStream(fileName, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
// This is the line that shows the exception
var readPathList = (List<FolderPath>)x.Deserialize(reader);
}
This is the XML Document
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfFolderPath xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FolderPath>
<Path>c:\FolderA</Path>
</FolderPath>
</ArrayOfFolderPath>