Answer the question
In order to leave comments, you need to log in
Why doesn't CSVHelper read fields from file?
I'm having a problem, csvhelper doesn't see any of the fields in my .csv file (there are many)
static OFSStoresDB ReadFile(string filename)
{
OFSStoresDB db = new OFSStoresDB();
StreamReader reader = new StreamReader(filename);
CsvReader csv = new CsvReader(reader);
csv.Read();
csv.ReadHeader();
csv.Configuration.HasHeaderRecord = true;
csv.Configuration.BadDataFound = null;
// Log missing field.
csv.Configuration.MissingFieldFound = (headerNames, index, context) =>
{
Console.WriteLine($"Field with names ['{string.Join("', '", headerNames)}'] at index '{index}' was not found. ");
};
while (csv.Read())
{
#region Read raw data
var timestampConverter = new TimestampConverter();
DateTime reportExtractedAt = csv.GetField<DateTime>("Report_Extracted_At", timestampConverter);
// Source Store
string srcStoreId = csv.GetField("Src_Store_Id");
string srcStoreName = csv.GetField("Src_Store_Name");
.... System.ArgumentNullException: 'Value cannot be null. Parameter name: value'
Field with names ['Report_Extracted_At'] at index '0' was not found.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question