mperdeck / LINQtoCSV

Popular, easy to use library to read and write CSV files.
197 stars 112 forks source link

Trailing comma in header can cause unknown ArgumentNullException #23

Open natedotzlaf opened 10 years ago

natedotzlaf commented 10 years ago

When creating test files I inadvertently left data on one of the data lines - which inserted an additional comma on the header line. When testing I received the unhelpful message "Value cannot be null.\r\nParameter name: key".

image

After digging around I found the culprit in FieldMapper.cs on line 413,

if (!m_NameToInfo.ContainsKey(row[i].Value))

Specifically, the extra comma in the header meant that row[i]Value evaluated as null.

While my case was certainly a fringe case the issue is easily solved be adding an additional exception type and checking for null prior to evaluating the column header.

Would be happy to submit a pull request if you'd like.

mperdeck commented 10 years ago

Sounds fine to me, go for it.