Skip to content

[BUG] - empty row in csv causing error of KeyNotFoundException #914

@jzhouw

Description

@jzhouw

Description

didn't find IgnoreEmptyRow option for Configuration and an empty row will cause this error with below code:

var importer = MiniExcel.Importers.GetCsvImporter();
var query = importer.Query(stream, hasHeader);
var result = await query.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToDynamicListAsync();

Expected Behavior

Actual Behavior

Workarounds

remove the empty row works

Environment (please fill the following information):

  • MiniExcel Version: MiniExcel.Csv, 2.0.0-preview.2
  • .NET Version: .NET8
  • OS: Windows

Files and/or Screenshots

this is an empty row in the csv

Additional Context

stack trace:

System.Collections.Generic.KeyNotFoundException:
at System.ThrowHelper.ThrowKeyNotFoundException (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Collections.Generic.Dictionary2.get_Item (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at MiniExcelLib.Csv.CsvReader+<Query>d__12.MoveNext (MiniExcel.Csv, Version=2.0.0.0, Culture=neutral, PublicKeyToken=e7310002a53eac39) at MiniExcelLib.Csv.CsvImporter+<Query>d__19.MoveNext (MiniExcel.Csv, Version=2.0.0.0, Culture=neutral, PublicKeyToken=e7310002a53eac39) at System.Linq.Enumerable+EnumerablePartition1.ToList (System.Linq, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Linq.Dynamic.Core.DynamicEnumerableAsyncExtensions+d__81.MoveNext (System.Linq.Dynamic.Core, Version=1.4.5.0, Culture=neutral, PublicKeyToken=0f07ec44de6ac832) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions