CSVHelper 7.1.1 - Header matching [id] names at index 0 was not found

眉间皱痕 提交于 2019-12-13 05:11:12

问题


I have an exception thrown when loading this CSV file :/ which is quite simple :

 public class BreederTemp
    {
        public BreederTemp ()
        {

        }
        public int Id { get; set; }
        public string Affix { get; set; }
        public bool Affix_Prefix { get; set; }
    }

public sealed class BreederClassMap : ClassMap<BreederTemp>
    {
        public BreederClassMap()
        {
            AutoMap();
            Map(m => m.Id);
            Map(m => m.Affix);
            Map(m => m.Affix_Prefix);
        }
    }

 class Program
    {
        static void Main(string[] args)
        {
          // [...]
          System.IO.TextReader textReader = new StreamReader(CsvFile, Encoding.Default);
          var csv = new CsvReader(textReader);
          csv.Configuration.RegisterClassMap<BreederClassMap>();
          csv.Configuration.Delimiter = ";";
          csv.Configuration.Encoding = Encoding.Default;
          csv.Read();

          var packs = csv.GetRecords<BreederTemp>().ToList();
          // Header matching [id] names exception 
        }
    }

Here is the CSV test file I'm using. I tried to export from XLSS to CSV-UTF8 or CSV without any changes.

Id;Affix;Affix_Prefix
1;(sans affixe);0
2;Des garrigues du loup de canebas;0
3;De Dan Jourdain;0

Did I miss something ? thanks for help

来源:https://stackoverflow.com/questions/51582272/csvhelper-7-1-1-header-matching-id-names-at-index-0-was-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!