CsvHelper: No members are mapped for type

You need to use Properties instead of fields in the object model as by default, it will map the matching public members

public class CsvLine {
    public string Solution { get; set; }
    public string Project { get; set; }
    public string DependsOnProject { get; set; }
    public string Weight { get; set; }
    public string DependsOnPackage { get; set; }
    public string PackageVersion { get; set; }
}

You should also read up on mapping your classes to the csv file.

CsvHelper: Class Mapping


Nkosi explained that CsvHelper maps to properties by default.

I've encountered the Enumeration yielded no results message in the debugger in the past. The message is misleading. There are records even though the debugger says there aren't. You iterate over the IEnumerable with foreach or call .ToArray() or .ToList() on it to load all records, eg:

var records = csvReader.GetRecords<CsvLine>();
foreach(var record in records)
{
     ...
}

Or

var records = csvReader.GetRecords<CsvLine>().ToArray();

You can force the debugger to show all items in an IEnumerable in the Watch, Quick Watch or Immediate window by adding the results format specifier, eg:

records,results

Be careful because this will execute the IEnumerable and return all results.

You can find this, and other tricks in 7 Hidden Gems in Visual Studio 2017

Tags:

C#

Csvhelper