Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StackOverflow Exception CSVHelper Writer

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;
}
like image 285
darren Avatar asked Oct 23 '25 05:10

darren


1 Answers

My problem was that the class I wanted to write didn't have a parameterless constructor.

like image 83
Daryl Avatar answered Oct 24 '25 18:10

Daryl