FileHelpers - "FieldConverter" is not valid for this ad type

I am trying to set the date format of the CSV file I am reading using the FieldConverter attribute, but I get the following error:

FieldConverter attribute is not valid for this ad type. This is valid only for 'field' declarations.

Any idea why this is happening and how I can fix it?

[DelimitedRecord(",")] [IgnoreFirst(1)] public class SomeViewModel { public int account { get; set; } [FieldConverter(ConverterKind.Date, "dd-MM-yyyy")] public DateTime doc_dte { get; set; } } 
+5
source share
1 answer

As you can see in the error message, you cannot use the FieldConverter on property attribute, only in the field. So, just change your property to field:

 [FieldConverter(ConverterKind.Date, "dd-MM-yyyy")] public DateTime doc_dte; 
+11
source

All Articles