I have a 2D array (a matrix) that I code to xml using XmlSerializer. When I de-serialize the string I get errors sometimes.
Like the following. It says XML-Document is bad because it contains a hex value 0x00
.
System.InvalidOperationException: Fehler im XML-Dokument (1,18449). ---
System.Xml.XmlException: '.', hexidezimaler Wert 0x00, ist ein ungültiges
Zeichen. Zeile 1, Position 18449.
bei System.Xml.XmlTextReaderImpl.Throw(Exception e)
bei System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
bei System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String[] args)
Possible solution
The error parts is this:
<anyType xsi:type="xsd:string">�</anyType>
Does that mean �
is not serializable or is the string I'm trying to serialize bad ?
What can I do to avoid having this exception ?
My code:
// serialize
StringBuilder builder = new StringBuilder(512 * 1024);
StringWriter writer = new StringWriter(builder);
object[][] array = table.ToArray(true);
try
{
new XmlSerializer(typeof(object[][])).Serialize(writer, array);
return builder.Replace(Environment.NewLine, string.Empty).ToString();
}
catch (Exception exception) { return exception.Message; }
finally
{
writer.Close();
writer.Dispose();
}
// de-serialize
StringReader reader = new StringReader(xml);
object[][] array = (object[][])new XmlSerializer(typeof(object[][])).Deserialize(reader);
reader.Close();
reader.Dispose();