Azure Web作业无法正确读取csv [英] Azure Web Jobs cannot read csv properly

查看:111
本文介绍了Azure Web作业无法正确读取csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新版本的CsvHelper库,但是Azure WebJob在读取我的csv文件时遇到了麻烦.

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

它表示无效的DateTime格式.尽管我有101%的信心,我的csv具有正确的DateTime格式.

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

我相信CsvHelper会导致此问题,但我真的不知道.

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

如果需要更多信息,请告诉我.

If more information is needed please let me know.

推荐答案

对于这样的问题,如果我们没有可以重现该问题的样本,那么我们很难回答.因此,在这里,我将仅向您分享一种自行解决问题的有效方法.

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.

首先,该问题不是由Web作业引起的,因此您应该首先在本地对其进行调试.

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

1,创建一个简单的控制台应用程序进行测试.

1, Create a simple console app for test.

2,下载CsvHelper库的源代码,在VS中的相同解决方案中添加源项目,然后引用CsvHelper项目,如下所示:

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

3,在测试应用程序中,输入一些具有与Web作业相同功能的代码.以下是我用于演示的内容. Foo类包含DateTime属性:

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,根据堆栈跟踪,该错误发生在TypeConversion文件夹-> DateTimeConverter.cs文件中的ConvertFromString方法上. 打开此文件并设置断点,如下所示:

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:

引发异常的最后一个方法是DateTime.Parse( text, formatProvider, dateTimeStyle ). 现在,运行项目,并检查每个参数(尤其是文本")是否正确.

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.

这篇关于Azure Web作业无法正确读取csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆