diff --git a/CsvHelper.FastDynamic/CsvReaderExtensions.cs b/CsvHelper.FastDynamic/CsvReaderExtensions.cs index 2aeea5e..2067fa1 100644 --- a/CsvHelper.FastDynamic/CsvReaderExtensions.cs +++ b/CsvHelper.FastDynamic/CsvReaderExtensions.cs @@ -40,7 +40,14 @@ public static IEnumerable EnumerateDynamicRecords(this CsvReader csvRea for (var i = 0; i < csvHeader.FieldNames.Length; i++) { - values[i] = csvReader.Parser[i]; + if (i >= csvReader.Parser.Count) + { + values[i] = default; + } + else + { + values[i] = csvReader.Parser[i]; + } } record = new CsvRecord(csvHeader, values); @@ -105,7 +112,14 @@ public static async IAsyncEnumerable EnumerateDynamicRecordsAsync(this for (var i = 0; i < csvHeader.FieldNames.Length; i++) { - values[i] = csvReader.Parser[i]; + if (i >= csvReader.Parser.Count) + { + values[i] = default; + } + else + { + values[i] = csvReader.Parser[i]; + } } record = new CsvRecord(csvHeader, values);