所以这段代码昨晚起作用了,我醒来并再次开始处理它,突然之间,它在下一行抛出了NullReference异常
client = new WebClient();
这是该方法的完整代码
//Loop through all image URL's and download files.
int fileIndex = 0;
WebClient client;
foreach (string url in newProduct.aliImageURLs)
{
//Replace quotes with empty chars.
string formattedURL = url.Replace("\"", "");
Console.WriteLine(formattedURL);
//Get file extension
string extension = Path.GetExtension(formattedURL);
//Save local path
newProduct.localImagePaths[fileIndex] = "c:\\SSBDB\\Pictures\\" + newProduct.AliName + "\\" + fileIndex + extension;
//Set up Web Client
client = new WebClient();
//Download Files and increase index
client.DownloadFileAsync(new Uri(formattedURL), @"c:\SSBDB\Pictures\" + fileIndex + extension);
fileIndex++;
}