0

I'm doing file downloader and I set download percentage to form text for better looks updater.ActiveForm.Text = e.ProgressPercentage.ToString() + "%";

it works but after some time I get System.NullReferenceException. I tried searching but its so specific issue that I could not find answer in my case. How can I fix it? Thanks in advance

  • Did you read whole thing? – adrian luighi Jul 26 '17 at 23:29
  • I think what Max may mean is that the scope of e may terminate when the download is complete...in which case you get a NullReferenceException because you are counting on e.attribute and e is gone. Perhaps try wrapping your form text assignment in a while() that is testing e. [I did not create an 'answer' as this is a short, incomplete suggestion only.] – JasonInVegas Jul 26 '17 at 23:33
  • Some part of the above code is becoming null or going out of scope. You would need to post more of your code to be able to determine the problem. – Deolus Jul 26 '17 at 23:35
  • Does it ever start reporting progress again? (wrapping it in a null check first before assigning) Has the file finished downloading? – Travis Acton Jul 26 '17 at 23:36
  • No my file has not been downloaded once this appears and I'm using DownloadFileAsync function of WebClient. If you tell me what part of code you want I can edit post – adrian luighi Jul 26 '17 at 23:40
  • Also I dont get this issue when I use label instead of updater.ActiveForm. If I will not find solution I will have to use label instead – adrian luighi Jul 26 '17 at 23:42
  • Put a break point to that line, run in debug mode, and hover mouse over your variables and their properties. At first they will all have values, since you say it works initially. If nothing is null, continue with **F5**. Before it throws an exception, something will be `null`. Most likely `e`, or `ProgressPercentage`, but it could be also `ActiveForm`, or anything else. – z m Jul 27 '17 at 00:15

0 Answers0