FileHelpers - 'FieldConverter' is not valid on this declaration type
Asked Answered
A

1

5

I'm trying to set the date format of a CSV file I'm reading from via the FieldConverter attribute but I'm receiving the following error -

Attribute 'FieldConverter' is not valid on this declaration type. It is only valid on '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; }
}
Announcement answered 24/5, 2016 at 7:59 Comment(0)
S
11

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

[FieldConverter(ConverterKind.Date, "dd-MM-yyyy")]
public DateTime doc_dte;
Speedwriting answered 24/5, 2016 at 8:2 Comment(2)
/facepalm. Thanks!Announcement
@user1645888 Glad to have been of helpSpeedwriting

© 2022 - 2024 — McMap. All rights reserved.