phatcher/CsvReader

GetFieldIndex returns -1 when setting custom columns and specifying hasHeaders = true

janis-veinbergs opened this issue · 2 comments

Given I use hasHeaders: true for CsvReader constructor and want to manually specify columns with correct types, _fieldHeaderIndexes doesn't get populated that results in broken GetFieldIndex method.

Because given hasHeaders = true the _fieldHeaderIndexes gets populated (line 1592) only when no Columns have been added before.

My workaround is to initialize CsvReader with hasHeaders: false and then use csv.ReadNextRecord() before while loop:
while (csv.ReadNextRecord()) { ... }

I just ran into this bug as well. Thanks for providing a workaround.

@janis-veinbergs @BrianVallelunga Can you check the current code base, there are some fixes around this