【发布时间】:2012-03-26 23:52:12
【问题描述】:
如何使用windows生成的c#读取xml中的二进制数据¬()。 我正在尝试访问列出 windows reg 中的注册表项。 字符串值中弹出二进制数据。我可以使用 xml 序列化将其序列化为 () 但我无法将其反序列化回来? 谁能解释我出了什么问题,为什么?帮我解决这个问题。 非常感谢 :))) 读取时出错:
System.InvalidOperationException 未处理
Message="XML 文档中存在错误 (235, 28)。" 从文件中读取:
public diagnostics readregkey(diagnostics diagnostics, string filename)
{
diagnostics dia = null;
using (System.IO.StreamReader sr =
new System.IO.StreamReader(filename, Encoding.Unicode))
{
System.Xml.Serialization.XmlSerializer x =
new System.Xml.Serialization.XmlSerializer(typeof(diagnostics));
dia = x.Deserialize(sr) as diagnostics;
}
return dia;
}
写入文件:
public static void WriteRegKey(diagnostics diagnostics, string filename)
{
diagnostic.regKeys.Add(key(Registry.LocalMachine, sKeyGravitas));
diagnostic.regKeys.Add(key(Registry.CurrentUser, sKeyGravitas));
using (System.IO.StreamWriter sw =
new System.IO.StreamWriter(filename,false, Encoding.Unicode))
{
System.Xml.Serialization.XmlSerializer x =
new System.Xml.Serialization.XmlSerializer(typeof(diagnostics));
x.Serialize(sw, diagnostics);
}
}
【问题讨论】:
-
您有我们可以用来帮助您的示例代码/错误消息吗?
-
向我们展示您将其序列化出来的确切代码,然后再重新输入?这似乎不是一个孤立的问题:marc.info/?l=xalan-dev&m=98865838020552&w=2
-
这不是和你的另一个问题一样吗,stackoverflow.com/questions/9631122/… ??
标签: c# xml visual-studio-2008