Search code examples
c#csvdictionarymappingcsvhelper

CSVHelper says no map exists


I'm trying to get CSVHelper to read some files, but it keeps telling me that no properties are mapped for my custom class. However, when I look with debugger it definitely seems like the Map is there and correct, so I'm confused.

Here's some code.

CsvReader csv = new CsvReader(new StreamReader(ms));
csv.Configuration.HasHeaderRecord = true;
csv.Configuration.IsHeaderCaseSensitive = false;
csv.Configuration.SkipEmptyRecords = true;
csv.Configuration.TrimFields = true;
csv.Configuration.TrimHeaders = true;
csv.Configuration.WillThrowOnMissingField = false;
csv.Configuration.RegisterClassMap<SampleMap>();
readSamples = csv.GetRecords<Sample>().ToList(); //breaks here

Here's a truncated version of my Sample and SampleMap classes

namespace Parser.Models
{
    public class Sample
    {
        public string Number { get; set; }
        public string Discussion { get; set; }
        public string OrderNumber { get; set; }
    }

    public sealed class SampleMap : CsvClassMap<Sample>
    {
        public SampleMap()
        {
            Map(m => m.Discussion).Name("Cases::CaseDiscussion");
            Map(m => m.OrderNumber).Name("Orders::OrderNumber");
        }
    }
}

What's missing?


Solution

  • The fault is in my csv file, not my code. Please disregard. If you are having a similar issue, make sure to check your file. :)