2

For some reason an ArgumentException saying 'Parameter is not valid.' at Application.Run gets thrown when executing either this:

private void utilsTabBtn_Click(object sender, EventArgs e)
{
    utilitiesPanel.BringToFront();
}

or this:

private void utilsTabBtn_Click(object sender, EventArgs e)
{
    utilitiesPanel.Visible = true;
    accountcreatorPanel.Visible = false;
    aboutPanel.Visible = false;
}

after executing RequestCaptcha in this code:

private void accountcreatorStartBtn_Click(object sender, EventArgs e)
{
    accountcreatorStopBtn.Enabled = true;
    accountcreatorStartBtn.Enabled = false;
    recaptchaSolveBox.Enabled = true;
    recaptchaContinueBtn.Enabled = true;
    recaptchaRenewBtn.Enabled = true;
    MinimalID = accIndexOne.Value;
    CurrentID = MinimalID - 1;
    MaximalID = accIndexTwo.Value;
    RequestCaptcha();
    recaptchaBox.SizeMode = PictureBoxSizeMode.StretchImage;
}

where RequestCaptcha is:

private void RequestCaptcha()
{
    LatestKey = ((new Random()).Next() * (new Random()).Next());
    statusLbl.Text = "Captcha key: " + LatestKey.ToString();
    recaptchaBox.Image.Dispose();
    using (WebClient w = new WebClient())
    {
        w.DownloadFile(string.Format(RequestURL, LatestKey), Environment.CurrentDirectory + "/latestCaptcha.jpg");
    }
    try
    {
        recaptchaBox.Image = Image.FromFile(Environment.CurrentDirectory + "/latestCaptcha.jpg");
    }
    catch (Exception ex)
    {
        recaptchaBox.Image = recaptchaBox.ErrorImage;
        MessageBox.Show(ex.Message, this.Text + " - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

ALL controls, with exception to the buttons ending with 'TabBtn' and the panels, are in the panel I'm trying to hide.

0x47686F7374
  • 434
  • 2
  • 14
  • Have you tried putting a breakpoint at the initial event and then stepping into it? – Logarr Jul 09 '13 at 20:20
  • I stepped through the whole program, the exception gets thrown as soon as utilsTabBtn_Click finished. – 0x47686F7374 Jul 09 '13 at 20:23
  • I can't tell from the sample provided, but perhaps this answer will be of some use: [answer](http://stackoverflow.com/a/389561/1127924) – Logarr Jul 09 '13 at 20:29
  • I checked that answer earlier, but how could changing the panel's visibility interfere with the Form's messageloop? – 0x47686F7374 Jul 09 '13 at 20:36
  • I guess my next step would be to try those methods without triggering the captcha method and see if the error persists. As it stands you have a lot of stuff happening from a single event so it's not a very clean test. – Logarr Jul 09 '13 at 20:50
  • 1
    Post the stack trace. The *entire* one, not just up to the last statement that was still part of your code. – Hans Passant Jul 09 '13 at 21:10

1 Answers1

2

Inside RequestCaptcha() method you are actually disposing the image which is still being used by picture box.

recaptchaBox.Image.Dispose();

above line is not valid. alternatively you could set

pictureBox1.Image = null;

or if you intend really to dispose the image you can do the following

Image image = recaptchaBox.Image;
recaptchaBox.Image = null;
image.Dispose();

that should solve your problem :)

Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189