如何找到CsvHelper.TypeConversion.CsvTypeConverterException的更多详情?

How to find out more details on CsvHelper.TypeConversion.CsvTypeConverterException?

我正在尝试使用以下代码导入 CSV 文件:

using CsvHelper;
using CsvHelper.Configuration;
\\ ...
try
  {
     var csv = new CsvReader(csvReader, new CsvConfiguration { 
        HasHeaderRecord = false, Delimiter = ";" });
     records = csv.GetRecords<FileDataContainerDisplay>().ToList();
   }
catch (Exception)
   {
      throw new FileFormatException();
}

代码失败

Exception thrown: 'CsvHelper.TypeConversion.CsvTypeConverterException' in CsvHelper.dll

奇怪的是,代码用于处理以下类型的文件:

Date;CurveName;Gridpoint;Timebase;Value
1.1.1900 00:00:00;A;1;1;0.12
1.1.1900 00:00:00;A;1;2;0.23
1.1.1900 00:00:00;A;1;3;0.34
...

谁能指导我在哪里可以找到更多关于哪种类型转换失败的详细信息?

顺便说一句,FileFormatException的定义比较无聊:

public class FileFormatException : Exception
{ }

参考资料

看来问题是您的配置与您的文件不匹配。您的配置表明没有 header 记录,但您的文件似乎有一条 header 记录,因此它试图将单词 "Date" 读取为 DateTime。当我查看内部异常时,我获得了更多信息。

The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.

您应该在 FileFormatException class 中包含 innerException。

public class FileFormatException : Exception
{
    public FileFormatException(string message, Exception innerException) : base(message, innerException)
    {
    }
}

catch (Exception e)
{
   throw new FileFormatException("Error message", e);
}