using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Collections.ObjectModel;
using CsvHelper.Configuration;
using CsvHelper.Configuration.Attributes;
using CsvHelper.Expressions;
using CsvHelper.TypeConversion;
public static void Test()
var csvText = "some crap line\n\nCOL1,COL2,COl3\nval1,val2,val3\nval1,val2,val3\n\n";
Console.WriteLine(csvText);
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(csvText));
var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture)
using (var csv = new CsvReader(new StreamReader(stream), csvConfiguration))
Assert.AreEqual(3, csv.HeaderRecord.Length);
Assert.AreEqual(@"COL1,COL2,COl3", String.Join(",", csv.HeaderRecord));
Console.WriteLine($"csv.HeaderRecord.Length = {csv.HeaderRecord.Length}: \"{String.Join(",", csv.HeaderRecord)}\"");
Console.WriteLine($" csv.Parser.Count={csv.Parser.Count}");
Console.WriteLine("Read {0} rows", count);
Assert.AreEqual(2, count);
Console.WriteLine($"csvConfiguration.IgnoreBlankLines={csvConfiguration.IgnoreBlankLines}");
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("OS Version: {0}, NewLine: {1}", System.Environment.OSVersion, JsonConvert.SerializeObject(Environment.NewLine));
Console.WriteLine("{0} version: {1}", typeof(CsvReader).Assembly.GetName().Name, typeof(CsvReader).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];