问题
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