我有一些xml文件,我正试图在给定代码中进行以下的消毒。
using (StreamReader srFileContent = new StreamReader(filePath))
{
XmlSerializer serializer = new XmlSerializer(typeof(messageType));
messageType objMessage = (messageType)serializer.Deserialize(srFileContent);
}
在此文件定位于文件Path 文件不包含以下行
<?xml version="1.0"?>
<message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
这就是为什么我得到错误的原因。可以帮助我如何在解密给定文件流之前添加此行运行时间 。
以下给出错误 :
System.InvalidOperationException: There is an error in XML document (2, 2). ---> System.InvalidOperationException: was not expected. at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReadermessageType.Read161_message() --- End of inner exception stack trace --- at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader) at CCR2BB.frmMain.BWConvertProcess_DoWork()