Describe the bug
Reading records using csv.GetRecords<Type>() and I get CsvHelper.HeaderValidationException
To Reproduce
Steps to reproduce the behavior:
Unhandled Exception: CsvHelper.HeaderValidationException: Header with name 'Id' was not found. If you are expecting some headers to be missing and want to ignore this validation, set the configuration HeaderValidated to null. You can also change the functionality to do something else, like logging the issue.
at CsvHelper.Configuration.ConfigurationFunctions.HeaderValidated(Boolean isValid, String[] headerNames, Int32 headerNameIndex, ReadingContext context)
at CsvHelper.CsvReader.ValidateHeader(ClassMap map)
at CsvHelper.CsvReader.<GetRecords>d__63`1.MoveNext()
at csvtest.Program.Main()
Expected behavior
Records are parsed into class objects.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
my code:
file.csv
Id,Name
1,one
```C#
using System.IO;
using CsvHelper;
namespace csvtest
{
class Program
{
public static void Main()
{
using (var reader = new StreamReader("file.csv"))
using (var csv = new CsvReader(reader))
{
var records = csv.GetRecords
foreach(var r in records)
{
System.Console.WriteLine(r);
}
}
}
}
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
}
}
```
Try manually setting the delimiter, sometimes your OS settings for CSV's overwrites the default comma delimiter.
csv.Configuration.Delimiter = ",";
Try manually setting the delimiter, sometimes your OS settings for CSV's overwrites the default comma delimiter.
csv.Configuration.Delimiter = ",";
Thank you, this solved the issue for me.
Added a PR with updated docs: https://github.com/JoshClose/CsvHelper/pull/1349
Most helpful comment
Try manually setting the delimiter, sometimes your OS settings for CSV's overwrites the default comma delimiter.
csv.Configuration.Delimiter = ",";