Using FileHelpers.dll version 3.0.1.0, with .net 4.0.
Code to reproduce issue:
create a file Accounts.txt like this:
"AccountName","ExtraColumn"
"MR GREEN ","abc"
"MR SMITH ","def"
c# Account class :
[IgnoreFirst(1)]
[DelimitedRecord(",")]
[IgnoreEmptyLines()]
public class Account
{
[FieldQuoted('"', QuoteMode.OptionalForBoth, MultilineMode.NotAllow)]
public string AccountName;
}
To read the file:
string fname = @"C:\test\Accounts.txt";
FileHelperEngine engine = new FileHelperEngine(typeof(Account));
Account[] importNodes = (Account[])engine.ReadFile(fname); // XX
Now, I would have expected an exception to be raised at line XX, because there are more columns in the file (2), than columns in the "Account" class (1). However, there is no exception raised, and the extra column seems to get silently ignored.
If you change the Account class to remove the "FieldQuoted" attribute, then an exception is indeed raised, like:
[FileHelpers.BadUsageException] {"Line: 2 Column: 0. Delimiter ',' found after the last field 'AccountName' (the file is wrong or you need to add a field to the record class)"} FileHelpers.BadUsageException
Can anyone provide some insight ? Should the code with the FieldQuoted attribute indeed raise an exception ? Am I doing something wrong ?
EDIT : are there any workarounds, so that an error will be raised when there are more columns in the input file than expected ?