title: Using CSVHelper on file upload
body: <p>I am trying to use the CSVhelper plugin to read an uploaded CSV file. Here is my modelBinder class:</p>
  
  <pre><code>public class SurveyEmailListModelsModelBinder : DefaultModelBinder
  {
      public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
      {
          var csv = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
          var file = ((csv.RawValue as HttpPostedFileBase[]) ?? Enumerable.Empty&lt;HttpPostedFileBase&gt;()).FirstOrDefault();
  
          if (file == null || file.ContentLength &lt; 1)
          {
              bindingContext.ModelState.AddModelError(
                  "",
                  "Please select a valid CSV file"
              );
              return null;
          }
  
          using (var reader = new StreamReader(file.InputStream))
          using (var csvReader = new CsvReader(reader))
          {
              return csvReader.GetRecords&lt;SurveyEmailListModels&gt;().ToArray();
          }
      }
  }
  </code></pre>
  
  <p>These are the objects I am trying to map to:</p>
  
  <pre><code>public class SurveyEmailListModels
  {
      [Key]
      [CsvField(Ignore = true)]
      public int SurveyEmailListId { get; set; }
  
      [CsvField(Index = 0)]
      public int ProgramId { get; set; }
  
      [CsvField(Index = 1)]
      public virtual SurveyProgramModels SurveyProgramModels { get; set; }
  
      [CsvField(Index = 2)]
      public string SurveyEmailAddress { get; set; }
  
      [CsvField(Index = 3)]
      public bool SurveyResponded { get; set; }
  
  }
  </code></pre>
  
  <p>Inside the Visual Studio debugger I am getting an error:</p>
  
  <ul>
  <li><p><code>base   {"You must call read on the reader before accessing its data."} CsvHelper.CsvHelperException {CsvHelper.CsvReaderException}</code></p></li>
  </ul>