So, I read that I should not write my own CSV reader / writer, so I tried to use the CsvHelper library installed via nuget. A CSV file is a grayscale image, with the number of lines being the height of the image and the number of columns wide. I would like to read the values differently in one List<string> or List<byte> .
The code I have so far is:
using CsvHelper; public static List<string> ReadInCSV(string absolutePath) { IEnumerable<string> allValues; using (TextReader fileReader = File.OpenText(absolutePath)) { var csv = new CsvReader(fileReader); csv.Configuration.HasHeaderRecord = false; allValues = csv.GetRecords<string> } return allValues.ToList<string>(); }
But allValues.ToList<string>() throws:
CsvConfigurationException failed to execute using user code
An exception of type 'CsvHelper.Configuration.CsvConfigurationException' occurred in CsvHelper.dll, but was not processed in the user code
Additional Information: Types that inherit IEnumerable cannot be automatically mapped. Did you accidentally call GetRecord or WriteRecord, which act on one record, instead of calling GetRecords or WriteRecords, which act on the list of records?
GetRecords probably expects my own custom class, but I just want the values to be both a primitive type and a string. In addition, I suspect that the entire string is converted to a single string, and not each value is a separate string.
c # csv csvhelper
Ayb4btu
source share