title: c# Cannot apply indexing with [] to an expression of type 'object'
body: <p>I have a code written some time ago that worked:</p>
  
  <pre><code>IHTMLDocument3 doc3 = (IHTMLDocument3)doc;
              IHTMLDocument7 doc7 = (IHTMLDocument7)doc;
  
              IHTMLElementCollection elc;
              IHTMLElement el;
              IHTMLElement chld;
              IHTMLDOMNode dn;
  
  if ((chld = el.children[1].children[0].children[1]) != null
                  &amp;&amp; chld.tagName == "A"
                  )
  </code></pre>
  
  <p>Now C# (express 2008, .NET 3.5) complains that
  Cannot apply indexing with [] to an expression of type 'object'</p>
  
  <p>referring to el.children[1]....</p>
  
  <p>What would be the problem? I know that worked before.
  Thanks for any clues,</p>
  
  <p>UPDATE:
  I just tested in VS2012 and works, compiles and run just fine.</p>
  
  <pre><code>private void Form1_Load(object sender, EventArgs e)
  {
      IHTMLElement test = null;
  
      IHTMLElement xxx = test.children[1];
  
  }
  </code></pre>
  
  <p>CONFIRMED:
  The same code in VS2008 is not working. The only difference is that I had to re-generate mshtml.dll for each project, by using different VS command prompts (each for .NET version).</p>
  
  <p>Generation was done with the same command:</p>
  
  <pre><code>sn -k mykey.snk
  tlbimp.exe /out:mshtml.dll /keyfile:mykey.snk mshtml.tlb
  </code></pre>
  
  <p>I really don't understand... any help greatly appreciated!</p>