Исключение типа "system.outofmemoryexception" было вызвано при чтении XML-файлов.
I am trying to read xml files and load the data to data base. While reading and adding xml file to list of object. I get 'System.OutOfMemoryException'. I could have more than 6000000 xml files which I am not sure if possible please guide better way to optimize the code.
Что я уже пробовал:
foreach (var xml in xmlFiles) { try { XmlRootAttribute xRoot = new XmlRootAttribute { ElementName = "CASE", IsNullable = true }; XmlSerializer xs = new XmlSerializer(typeof(MyTable), xRoot); MyTable cs = new MyTable(); using (var sr = new StreamReader(xml)) { cs = (MyTable)xs.Deserialize(sr); // cases.Add(cs); LoadtToLocalDB(cs); } } catch (Exception ex) { using (var writer = new StreamWriter(errorLog, false)) { writer.WriteLine(xml); writer.WriteLine(ex.Message); writer.WriteLine("----------------------------------------------------------------------------------"); } } }