title: How to read huge CSV file with 29 million rows of data using .net
body: <p>I have a huge <code>.csv</code> file, to be specific a <code>.TAB</code> file with 29 million rows and the file size is around 600 MB. I would need to read this into an <code>IEnumerable</code> collection.</p>
  
  <p>I have tried <code>CsvHelper</code>, <code>GenericParser</code>, and few other solutions but always ending up with an Out of Memory exception</p>
  
  <p>Please suggest a way to do this</p>
  
  <p>I have tried </p>
  
  <pre><code>var deliveryPoints = new List&lt;Point&gt;();
  
  using (TextReader csvreader1 = File.OpenText(@"C:\testfile\Prod\PCDP1705.TAB")) //StreamReader csvreader1 = new StreamReader(@"C:\testfile\Prod\PCDP1705.TAB"))
  using (var csvR1 = new CsvReader(csvreader1, csvconfig))
  {
       csvR1.Configuration.RegisterClassMap&lt;DeliveryMap&gt;();
       deliveryPoints = csvR1.GetRecords&lt;Point&gt;().ToList();
  }
  
  using (GenericParser parser = new GenericParser())
  {
       parser.SetDataSource(@"C:\testfile\Prod\PCDP1705.TAB");
  
       parser.ColumnDelimiter = '\t';
       parser.FirstRowHasHeader = false;
       //parser.SkipStartingDataRows = 10;
       //parser.MaxBufferSize = 4096;
       //parser.MaxRows = 500;
       parser.TextQualifier = '\"';
  
       while (parser.Read())
       {
           var address = new Point();
           address.PostCodeID = int.Parse(parser[0]);
           address.DPS = parser[1];
           address.OrganisationFlag = parser[2];
           deliveryPoints.Add(address);
       }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>var deliveryPoints = new List&lt;Point&gt;();
  csvreader = new StreamReader(@"C:\testfile\Prod\PCDP1705.TAB");
  csv = new CsvReader(csvreader, csvconfig);
  
  while (csv.Read())
  {
       var address = new Point();
       address.PostCodeID = int.Parse(csv.GetField(0));
       address.DPS = csv.GetField(1);                
       deliveryPoints.Add(address);
  }
  </code></pre>