Abdullah
Abdullah

Reputation: 39

FileHelpers and data type exception

I'm using FileHelpers library to import a tab delimited file. I have enabled the ErrorMode.SaveAndContinue. The issue I'm facing is that when particular fields has invalid data type

 [FieldConverter(ConverterKind.Decimal)]
 public decimal? Price;

(e.g decimal? Price field has string value in it xxxxxx) in a single record, the library only checks against the first field value and throws internal exception which is logged into the ErrorManager.Errors.

I need to check the remaining fields as well on the same row and log their errors as well in the same cycle.

How can I do that?

** Please note that I have tried to writing CustomConverter but again I need to throw ConvertException so that it gets catched by ErrorManager and it just moves to next row.

The AfterReadRecord does not gets called because of the exception

Upvotes: 0

Views: 507

Answers (1)

Marcos Meli
Marcos Meli

Reputation: 3506

That behavior is by design from the first versions of the library, the exception is throw when found the problem or the error is logged if ErrorManager is present

The best way to solve your problem is to use a string field for Price and later do the validations you need in the AfterReadRecord method

For example

public class YourClass: INotifyRead
{
 [FieldConverter(ConverterKind.Decimal)]
 public string Price;

 void AfterReadRecord (...)
 // Validate inside this method
}

Upvotes: 1

Related Questions