You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var csv = new CsvReader(new StreamReader(filename));
var data = csv.GetRecords<string[]>();
var header = csv.FieldHeaders;
and I get an exception "You must call read on the reader before accessing its data. ". GetRecords docs say "Read method should not be used when using this."
The text was updated successfully, but these errors were encountered:
Having just dealt with a similar issue (#131), the issue is that GetRecords returns an IEnumerable constructed using the yield keyword. GetRecords calls Read as you iterate over the IEnumerable. Since you haven't iterated over the collection, Read hasn't been called.
It does seem like this is a common enough issue that the CsvReader's constructor may need to be populating the FieldHeaders property instead. IMHO, for most people attempting to get FieldHeaders, the value of doing so is to check for the presence of specific headers before reading data from the file. I'm assuming that there was a reason for writing it this way, and I'm curious to know what the reason is.
I have this code
and I get an exception "You must call read on the reader before accessing its data. ". GetRecords docs say "Read method should not be used when using this."
The text was updated successfully, but these errors were encountered: