I have several xml files and am trying to deserialize as shown below in this code.
using (StreamReader srFileContent = new StreamReader(filePath)) { XmlSerializer serializer = new XmlSerializer(typeof(messageType)); messageType objMessage = (messageType)serializer.Deserialize(srFileContent); }
Here, the locate at filePath file does not contain the following lines
<?xml version="1.0"?> <message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
and thatβs why I get the error. Can it help me how to add this line to runtime before deserializing the stream of the given file.
The error is given below:
System.InvalidOperationException: There is an error (2, 2) in the XML document. ---> System.InvalidOperationException: was unexpected. at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReadermessageType. Read161_message () --- End of internal check for exception stack --- in System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) on System.Xml.Serialization.XmlSerializer.Deserialize (TextReader textReader) in CCR2BB .frmMain.BWConvertProcess_DoWork ()
source share