Azure Web Jobs cannot read csv properly

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 15:39:01

问题


I am using the latest version of CsvHelper library and yet Azure WebJob making troubles reading my csv file.

It says not valid DateTime format. Though I am 101% sure that my csv has the right DateTime format.

I believe that the CsvHelper causes the issue but I don't really know..

If more information is needed please let me know.


回答1:


For such issue, it would be diffcult to us to answer if we don't have a sample that can reproduce the issue. So here I will just share you an effective way to troubleshoot by yourself.

First of all, the issue is not caused by web job, so you should debug it locally first.

1, Create a simple console app for test.

2, Download the source code of CsvHelper library, add the source project in same solution in VS then reference CsvHelper project like below:

3, In your test app, input some code with same functionality you use in web job. The below is what i use for demo. Foo class contains a DateTime property:

class Program
{
    static void Main(string[] args)
    {
        using (var reader = new StreamReader(@"C:\Users\toml\Desktop\test.csv"))
        using (var csv = new CsvReader(reader))
        {
            csv.Configuration.BadDataFound = null;
            var records = csv.GetRecords<Foo>();

            foreach (var item in records)
            {
                Console.WriteLine(item.Time);
            }
        }
        Console.ReadKey();
    }
}
public class Foo
{
    public int Id { get; set; }
    public string Name { get; set; }
    public DateTime Time { get; set; }
}

4, According the stack trace, the error occurs on ConvertFromString method which is in TypeConversion folder -> DateTimeConverter.cs file. Open this file and set breakpoint like below:

The last method that throws exception is DateTime.Parse( text, formatProvider, dateTimeStyle ). Now Run the project and check if each parametor, espectially "text", is expected.

It will provide more information for you to debug.



来源:https://stackoverflow.com/questions/54794398/azure-web-jobs-cannot-read-csv-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!