title: System.ArgumentOutOfRangeException StartIndex cannot be less than zero get On server, on localhost no error
body: <p>I have very strange problem, I'm downloading html from other website (it is not illegal). </p>
  
  <pre><code>string img_1 = startHTML.Substring(startHTML.IndexOf("img"));
  </code></pre>
  
  <p>It was working perfect, but suddanly it stop and show this error:</p>
  
  <blockquote>
    <p>System.ArgumentOutOfRangeException: StartIndex cannot be less than zero. Parameter name: startIndex at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) at System.String.Substring(Int32 startIndex) at</p>
  </blockquote>
  
  <p>The strange is that on localhost it is still working.</p>
  
  <p>I know what this error mean, and how to handle with it, but this time is totaly different.</p>
  
  <pre><code>try
      {
  
          string img_1 = startHTML.Substring(startHTML.IndexOf("img"));
          img_1 = img_1.Substring(0, img_1.IndexOf("&lt;/div&gt;"));
  
          if (img_1.Contains("&lt;a href="))
          {
  
  
          }
          else
          {
              string img_3 = "";
              string img_7 = img_1.Substring(img_1.IndexOf("src="));
  
              string img_2 = img_7.Substring(0, img_7.IndexOf(".jpg") + 4);
              img_3 = img_2.Substring(img_2.IndexOf("src=\"") + 5);
              img_3 = img_3.Trim();
  
              lastImage = img_3;
          }
      }
      catch (Exception ee)
      {
          try
          {
              string img_1 = startHTML.Substring(startHTML.IndexOf("class=\"poster\""));
              img_1 = img_1.Substring(0, img_1.IndexOf("&lt;/div&gt;"));
  
              if (img_1.Contains("&lt;a href="))
              {
  
              }
              else
              {
                  string img_3 = "";
                  string img_7 = img_1.Substring(img_1.IndexOf("src="));
  
                  string img_2 = img_7.Substring(0, img_7.IndexOf(".jpg") + 4);
                  img_3 = img_2.Substring(img_2.IndexOf("src=\"") + 5);
                  img_3 = img_3.Trim();
                  lastImage = img_3;
              }
  
              lblMsg.Text = "NO IMAGE! " + Convert.ToString(ee);
          }
          catch(Exception eeеее)
          {
              lblMsg.Text = "NO IMAGE! " + Convert.ToString(eeеее);
          }
      }
  
      return lastImage;
  </code></pre>
  
  <p>On <strong>localhost</strong> on the first <strong>try</strong>, there is no <strong>catch</strong>. But on the <strong>server</strong> the second <strong>try</strong> have this problem, and it should not go on the second <strong>try</strong>, because the first <strong>try</strong> on localhost execute correct</p>
  
  <p>I've red here and search in google, but didn't found anything. Can be some cultural problem, if it is, can somebody give where to read how to fix it? And is it possible, the <strong>startHTML</strong> string to become empty in second try I've copy the error and paste it on google. I've opened all links on first page. But no one answear my question. </p>