{"There is an error in XML document (22, 8)."}
Inner Exception
{"Input string was not in a correct format."}

file attachments

Closed Dec 7, 2011 at 3:54 PM by darick_c


enooijen wrote Nov 14, 2010 at 10:15 AM

I had the same issue. In my case it was caused by movies without a score (returned value "<score></score>").
This can be fixed by an update to the Score attribute of a movie:
    public string ScoreElement
            if (Score == null) 
                return String.Empty; 
                return Score.ToString(); 
            if (value == null || value.Length == 0)
                Score = null;
                Score = Convert.ToDecimal(value);

    public decimal? Score{ get; set; }

wrote Dec 1, 2010 at 5:08 PM

wrote Dec 2, 2010 at 7:48 AM

wrote Jan 1, 2011 at 11:48 PM

wrote Jan 11, 2011 at 11:24 PM

jonnyc wrote Jan 11, 2011 at 11:24 PM

I had this issue too and the way I solved it was to remove these empty elements before deserializing. With the help of this sample code (http://stackoverflow.com/questions/2966056/deserialize-xml-with-empty-elements-in-c), I ended up with...
    public static T Deserialize<T>(string xml)
        XmlSerializer xs = new XmlSerializer(typeof(T));
        string cleanXml = xml;
        cleanXml = Regex.Replace(xml, @"<[a-zA-Z].[^(><.)]+/>", string.Empty);
        cleanXml = Regex.Replace(xml, @"<([a-zA-Z].[^(><.)]+)></\1>", string.Empty);
        MemoryStream memoryStream = new MemoryStream((new UTF8Encoding()).GetBytes(cleanXml));
        XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
        return (T)xs.Deserialize(memoryStream);
    public TmdbMovie[] MovieSearch(string title)
TmdbMovieSearchResults search = XmlUtility.Deserialize<TmdbMovieSearchResults>(xml);
This seems to be the best way in my opinion since you never know which elements are going to be empty and it will keep your serialization classes untouched.

I've attached a diff file for the complete changes, although I've only modified the MovieSearch method in the diff to use the new method.

darick_c wrote Oct 19, 2011 at 4:09 AM

I have re-written the code to use json instead of xml, hopefully that will help. Also, I have changed some of the property types.

wrote Dec 7, 2011 at 3:54 PM

wrote Feb 14, 2013 at 2:05 AM

wrote May 16, 2013 at 7:43 AM