CsvHelper
CsvHelper copied to clipboard
MissingFieldFund = Null not working proper;y
Hi Josh, I've started using your library today and am running into a problem. I have a CSV with lots of whitespace. I'm using MissingFieldFound and still getting an exception stating:
"Unhandled exception. CsvHelper.MissingFieldException: Field at index '2' does not exist. You can ignore missing fields by setting MissingFieldFound to null."
Am I missing something? My code is :
static object ReadCsv(string csvFileName)
{
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
HasHeaderRecord = false,
MissingFieldFound = null
};
using (var reader = new StreamReader(csvFileName))
using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
{
var records = csv.GetRecords<CSV>().ToArray();
Console.WriteLine(records.ToString());
}
return 0;
}
You need to replace new CsvReader(reader, CultureInfo.InvarientCulture) with new CsvReader(reader, config).