title: Can I use a ClassMap for writing with CsvHelper?
body: <p>I am attempting to use CsvHelper to improve my manual conversion process from objects to csv records/rows. I have created a complex <code>ClassMap</code> that I wanted to use to write a list of objects out to a file. How can I add the <code>ClassMap</code> to the CsvHelper instance's Configuration for writing?</p>
  
  <p>I am getting the following exception and message now:</p>
  
  <pre><code>public class SpecimenMap : ClassMap&lt;Specimen&gt;
  {
      public SpecimenMap()
      {
          Map(s =&gt;
                  DataFunctions.GetSiteByName(s.SiteName).RecordNo.ToString() + "-" +
                      s.SpecimenNumber.ToString()).
                      Index(0).Name("recordNumber");
  
          Map(s =&gt; 
                  s.RecordNo.ToString()).
                      Index(1).Name("specimenNumber"); 
  </code></pre>
  
  <p>/* many more, but I set a breakpoint on the first 'Map' and it throws the exception. I also tried commenting out the first 'Map' and running the second (since the first includes calls to external functions), it had identical results. */
  ....</p>
  
  <pre><code>        using (var writer = new StreamWriter(localFileLocation))
          using (var csv = new CsvWriter(writer))
          {
              csv.Configuration.RegisterClassMap&lt;SpecimenMap&gt;(); // this line throws exception
              csv.WriteRecords(specimen);
          }
  </code></pre>
  
  <p>Exception Thrown:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: No members were found in expression
    '{expression}'.</p>
  </blockquote>
  
  <p>In my research I found this code but I don't know how to interpret the exception. Something about the Stack size after doing some kind of Reflection (Line 34).
  <a href="https://github.com/JoshClose/CsvHelper/blob/master/src/CsvHelper/Configuration/ClassMap%601.cs" rel="noreferrer">https://github.com/JoshClose/CsvHelper/blob/master/src/CsvHelper/Configuration/ClassMap%601.cs</a></p>