FileNotFoundException when Deserializing XML string

0

I'm experiencing a strange issue while deserializing an XML string. The issue dissappears when clearing the Local temp folder. The error appears again after restarting the PC and i need to clear the local temp folder again to make it run again.

System.InvalidOperationException: There is an error in XML document (0, 0). ---> System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderReportDescription.Read97_ReportDescription()
   --- 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 Reporting.DataModel.XmlDBReportRepository.Deserialize[T](String xml) in C:\Projects\.NET Tools\SuperlinkGraph\Reporting.DataModel\XmlDBReportRepository.cs:line 181

I printed out the XML string to a text file to checkout whether it's valid or not. I validated the XML string using an XML validator at seems to be correct. Here is the two first lines of the XML.

<?xml version="1.0" encoding="utf-16"?>
<ReportDescription xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

I don't understand why the application throws FileNotFoundException when i'm trying to deserialize a string variable. I used the Process Monitor Tool to try to track the issue without any luck.

public T Deserialize<T>(string xml)
{
    try
    {
        XmlSerializer ser = new XmlSerializer(typeof(T), GetExtraTypes());
        File.AppendAllText(@"C:\Temp\Xml.txt", xml);                    
        return (T)ser.Deserialize(new StringReader(xml)); //Line 181  
    }
    catch (Exception e)
    {
        File.AppendAllText(@"C:\Temp\Exception.txt", e.ToString());
        throw;
    }
}

I'm not sure how to deal with that issue. I hope anyone can guide me through how to analyze the issue in more details or where to start to look.

c#
xml
serialization
deserialization
filenotfoundexception
asked on Stack Overflow Jun 19, 2019 by MOSA

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0