Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when reading file with Quoted field at end of first row and SkipEmptyLines=false #73

Open
bornfromanegg opened this issue Nov 28, 2019 · 0 comments

Comments

@bornfromanegg
Copy link

bornfromanegg commented Nov 28, 2019

If you attempt to read a file containing the following:

North,"South"
East,West

using the code:

var csvReader = new CsvReader(new StreamReader(<insert-file-here>), hasHeaders: false)
{
  SupportsMultiline = false,
  SkipEmptyLines = false
};

while (csvReader.ReadNextRecord())
{
  var s = csvReader[0];
}

Then you receive the error:

LumenWorks.Framework.IO.Csv.MissingFieldCsvException: The CSV appears to be corrupt near record '1' field '0 at position '15'. Current raw data : 'North,"South"
    East,West'.
       at LumenWorks.Framework.IO.Csv.CsvReader.HandleParseError(MalformedCsvException error, Int32& pos) in C:\Devel\OpenSource\CsvReader\code\LumenWorks.Framework.IO\Csv\CsvReader.cs:line 1800
       at LumenWorks.Framework.IO.Csv.CsvReader.HandleMissingField(String value, Int32 fieldIndex, Int32& currentPosition) in C:\Devel\OpenSource\CsvReader\code\LumenWorks.Framework.IO\Csv\CsvReader.cs:line 1875
       at LumenWorks.Framework.IO.Csv.CsvReader.ReadField(Int32 field, Boolean initializing, Boolean discardValue) in C:\Devel\OpenSource\CsvReader\code\LumenWorks.Framework.IO\Csv\CsvReader.cs:line 1193
       at LumenWorks.Framework.IO.Csv.CsvReader.get_Item(Int32 field) in C:\Devel\OpenSource\CsvReader\code\LumenWorks.Framework.IO\Csv\CsvReader.cs:line 644
       at ConsoleApp4.Program.Main(String[] args) in C:\Users\paul8828\source\repos\ConsoleApp4\ConsoleApp4\Program.cs:line 31

Looking at the stacktrace suggests that the reader thinks it is trying to read a missing field. And in fact, if you set MissingFieldAction to ReplaceByNull, then the error goes away, but the reader actually reads three rows. An entirely blank row is "read" inbetween row 1 and 2 in the source file.

I would like to be able to read using SkipEmptyLines=false, but that is a problem if the reader sometimes inserts extra blank rows.

Note this only seems to happen under the exact conditions described.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant