DownloadFileAsync Callbacks return -1 for TotalBytesToReceive in Mono 5.12+

swintersswinters USMember ✭✭

This worked using mono 5.10, but as of 5.12 it appears broken. Given the following code:

void TestDownload()
{
    WebClient webClient = new WebClient();
    webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
    webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted;
    webClient.DownloadDataAsync(new Uri("some file url"));
}

void WebClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
    Console.WriteLine("File Download Complete");
}

void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
    Console.WriteLine($"File Download Progress: {e.BytesReceived}:{e.TotalBytesToReceive}, state: {e.UserState}");
}

I get a whole lot of this:

File Download Progress: 938392:-1, state: 
File Download Progress: 954776:-1, state: 
File Download Progress: 966896:-1, state: 
File Download Progress: 983280:-1, state: 
File Download Progress: 995400:-1, state: 
File Download Progress: 1005568:-1, state: 
File Download Progress: 1005568:1005568, state:

If I use mono 5.10 it gives me the correct value:

File Download Progress: 938392:1005568, state: 
File Download Progress: 954776:1005568, state: 
File Download Progress: 966896:1005568, state: 
File Download Progress: 983280:1005568, state: 
File Download Progress: 995400:1005568, state: 
File Download Progress: 1005568:1005568, state: 
File Download Progress: 1005568:1005568, state:

I looked at the differences in WebClient.cs, but didn't see anything obvious that changed. Any ideas?

Best Answer

Answers

Sign In or Register to comment.