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
my code:
foreach (var xml in xmlFiles)
{
{
try
{
XmlRootAttribute xRoot = new XmlRootAttribute
{
ElementName = "CASE",
IsNullable = true
};
{
XmlRootAttribute xRoot = new XmlRootAttribute
{
ElementName = "CASE",
IsNullable = true
};
XmlSerializer xs = new XmlSerializer(typeof(MyTable), xRoot);
MyTable cs = new MyTable();
MyTable cs = new MyTable();
using (var sr = new StreamReader(xml))
{
cs = (MyTable)xs.Deserialize(sr);
// cases.Add(cs);
LoadtToLocalDB(cs);
}
{
cs = (MyTable)xs.Deserialize(sr);
// cases.Add(cs);
LoadtToLocalDB(cs);
}
}
catch (Exception ex)
{
catch (Exception ex)
{
using (var writer = new StreamWriter(errorLog, false))
{
writer.WriteLine(xml);
writer.WriteLine(ex.Message);
writer.WriteLine("----------------------------------------------------------------------------------");
}
}
}
{
writer.WriteLine(xml);
writer.WriteLine(ex.Message);
writer.WriteLine("----------------------------------------------------------------------------------");
}
}
}
Jignesh KumarRank #91 · 22.9K reputationPosted Apr 26, 2019, 10:01 PM EDT
Amit GuptaRank #190 · 12.8K reputationPosted Apr 26, 2019, 4:31 AM EDT
Amit KumarRank #459 · 5.4K reputationPosted Apr 26, 2019, 9:49 PM EDT
Sam V20 reputationPosted Apr 30, 2019, 10:35 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts