C# “有吗?”;“杀死字符串”;不可(反)序列化的?

C# “有吗?”;“杀死字符串”;不可(反)序列化的?,c#,xml,C#,Xml,我有一个2D数组(一个矩阵),我用它编码成xml。反序列化字符串时,有时会出现错误。如下所示。它说XML文档不好,因为它包含一个十六进制值0x00 System.InvalidOperationException: Fehler im XML-Dokument (1,18449). --- System.Xml.XmlException: '.', hexidezimaler Wert 0x00, ist ein ungültiges Zeichen. Zeile 1, Pos

我有一个2D数组(一个矩阵),我用它编码成xml。反序列化字符串时,有时会出现错误。
如下所示。它说XML文档不好,因为它包含一个十六进制值
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)

错误部分如下:

<anyType xsi:type="xsd:string">&#x0;</anyType>
// 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();
是的,XML文档中不允许存在,ASCII代码0就是其中之一。(感谢knittl和pln在中提供位置)

字符串包含十六进制值0x00是否有原因?对于字符串来说,这似乎是一个奇怪的值,因为它被用作终止字符


我建议您仔细看看,如果字符串确实需要包含这些字符,那么您可以选择在序列化期间将数据转换为base64,并在反序列化期间将其转换回。

XML不允许值为0的实体。NUL teminator字符可能与我很好奇为什么序列化对象会导致
。您的数组中存储了什么类型的值?@JLRishe它来自数据库。