最近切换到了.NET Core 3 Preview 5,看来TextFieldParser并没有读取所有数据,这导致数组超出范围异常。
我了解到向.NET Core 3的迁移似乎是合乎逻辑的;但是,我相信它使用的是相同的Microsoft.VisualBasic.dll。我没有在.NET Core GitHub上看到错误报告或问题。
有什么想法吗?我想念的东西简单吗?谢谢!
public void Download()
{
var metadataList = RetrieveTickerMetadata();
foreach (var metadata in metadataList)
{
var req = WebRequest.Create(metadata.Url);
var resp = req.GetResponse();
var sr = new StreamReader(resp.GetResponseStream() ?? throw new InvalidOperationException());
using (var parser = new TextFieldParser(sr))
{
parser.TextFieldType = FieldType.Delimited;
parser.SetDelimiters(",");
// skip header
var fields = parser.ReadFields();
while (!parser.EndOfData)
{
//Process row
fields = parser.ReadFields();
// EXCEPTION BEING THROWN HERE...
if (fields[17] == "None")
continue;
var eps = new EPSDiluted()
{
Ticker = metadata.Ticker,
QuarterEnd = Convert.ToDateTime(fields[0]),
EPS = decimal.Parse(fields[17])
};
_financeContext.EPSDiluted.Add(eps);
}
}
sr.Close();
_financeContext.SaveChanges();
}
}