CsvHelper icon indicating copy to clipboard operation
CsvHelper copied to clipboard

CsvReader.ColumnCount is not set

Open chickenpotpie opened this issue 3 years ago • 4 comments

A comment on IReaderRow.ColumnCount says, "Gets the column count of the current row. This should match CsvHelper.IParser.Count." I'm finding on CsvReader that ColumnCount is zero even when CsvReader.Parser.Count has a correct value.

chickenpotpie avatar Apr 21 '21 13:04 chickenpotpie

It looks like it's only set when DetectColumnCountChanges is true.

chickenpotpie avatar Apr 21 '21 13:04 chickenpotpie

I have the same issue while calling csvReader.ColumnCount. This property name is confusing.

tonyqus avatar Aug 28 '21 00:08 tonyqus

Agreed, this should be set on every record read. I don't want exception to be thrown on csvHelper.Read(), which occurs when DetectColumnCountChanges=true is set. Which short circuits my ability to deal with that bad record. So was figuring it would be set on every record read to determine if it matches my expected column count, but alas, it is not. So I can no longer handle bad records where the column count is incorrect :(

xantari avatar Feb 19 '22 22:02 xantari

Well over a year old, but I just ran into this issue. My workaround (and correct me if this is incorrect) was to use csvReader.Parser.Count

blakesparkes avatar Jul 22 '22 13:07 blakesparkes

Same here! It's confusicating.

rathga avatar Dec 22 '22 11:12 rathga

Fixed.

JoshClose avatar Jan 24 '24 20:01 JoshClose