Source Error:
The input string had the wrong format.
Description: An unhandled exception occurred during the execution of the current web request. Examine the stack trace for more information about this error and the code snippet that caused it.
Exception Details: System.FormatException: The input string had an invalid format.
Строка 192: using (StreamReader sr2 = new StreamReader(stream)) Строка 193: { Строка 194: adsList = (List<Ad>)serializer.Deserialize(sr2); Строка 195: sr2.Close(); Строка 196: } Full listing:
[Serializable()] public class Ad { [XmlElement("Id")] public int Id { get; set; } // это поле встречается не во всех нодах xml файла [XmlElement("Country")] public string Country { get; set; } } public static void AdGet(string FileUrl, string filesrc) { XmlRootAttribute xRoot = new XmlRootAttribute(); xRoot.ElementName = "Ads"; xRoot.IsNullable = true; XmlSerializer serializer = new XmlSerializer(typeof(List<Ad>),xRoot); String strResult; WebResponse objResponse; var adsList = new List<Ad>(); WebRequest objRequest = HttpWebRequest.Create(FileUrl); objResponse = objRequest.GetResponse(); using (StreamReader sr = new StreamReader(objResponse.GetResponseStream())) { strResult = sr.ReadToEnd(); strResult = strResult.Replace(" formatVersion=\"3\"", ""); sr.Close(); } MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream); writer.Write(strResult); writer.Flush(); stream.Position = 0; using (StreamReader sr2 = new StreamReader(stream)) { adsList = (List<Ad>)serializer.Deserialize(sr2); sr2.Close(); } }