I am getting a stackoverflow exception when writing a new csv file using csvhelper. Exception is raised on the line:
csv.WriteRecords(listToSave)
Originally thought it was down to using generic List but have also tried with a concrete list and can replicate it with any sized list and any type of list.
All lists are created using Entity Framework .ToList() have also tried AsEnumerable() etc...
Not sure if I'm missing something blindingly obvious?
Any help to resolve, much appreciated.
public string SaveTemporaryCsvToFileSystem<T>(IEnumerable<T> listToSave, string fileName)
{
//Store in folder
string folder = "C:\\inetpub\\wwwroot\\Content\\EmailOutput\\Temporary Files\\";
string filePath = fileName + DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + ".CSV";
if(!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
using (TextWriter writer = new StreamWriter(folder + filePath))
{
var csv = new CsvWriter(writer);
csv.WriteRecords(listToSave);
}
var zippedFile = ZipSecurely(folder + filePath);
DeleteUnsecureFile(folder + filePath);
return zippedFile;
}
My problem was that the class I wanted to write didn't have a parameterless constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With