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

Confusing exception when DateTimeOffsetConverter can't convert value #2321

Open
Bouke opened this issue Feb 6, 2025 · 1 comment
Open

Confusing exception when DateTimeOffsetConverter can't convert value #2321

Bouke opened this issue Feb 6, 2025 · 1 comment

Comments

@Bouke
Copy link

Bouke commented Feb 6, 2025

When a value cannot be converted to a DateTimeOffset, the exception message shows "Text: ''", instead of the actual column's value. Also, the member's name is not populated, making it difficult to debug.

Repro

[Test]
public void Repro()
{
    var input = """
                Timestamp
                01-01-0001 00:00
                """;
    using var reader = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(input)));
    using var csv = new CsvReader(reader, CultureInfo.InvariantCulture);
    var records = csv.GetRecords<Record>().ToArray();
}

record Record(DateTimeOffset Timestamp);

Throws:

CsvHelper.TypeConversion.TypeConverterException : The conversion cannot be performed.
    Text: ''
    MemberName: 
    MemberType: 
    TypeConverter: 'CsvHelper.TypeConversion.DateTimeOffsetConverter'
IReader state:
   ColumnCount: 1
   CurrentIndex: 0
   HeaderRecord:
["Timestamp"]
IParser state:
   ByteCount: 0
   CharCount: 26
   Row: 2
   RawRow: 2
   Count: 1
   RawRecord:
01-01-0001 00:00

When there are a lot of columns, it is quite difficult to understand the problem. The column's value is not empty, but something that could not be parsed. And I would expect the MemberName / MemberType to also not be empty.

@JoshClose
Copy link
Owner

That works fine for me when I run it in LINQPad.

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

2 participants