title: WebBrowser document cast not valid
body: <p>I've got a WebBrowser control on my page. To fire some javascript on a page displayed in the browser control, I call this.myBrowser.Document.InvokeScript("Test");</p>
  
  <p>This works on my dev box with IE7, but on a seperate test machine I get the following error:</p>
  
  <pre><code>Exception Type: System.InvalidCastException
  Message: Specified cast is not valid.
  Source: System.Windows.Forms
  Stack Trace: 
     at System.Windows.Forms.UnsafeNativeMethods.IHTMLDocument2.GetLocation()
     at System.Windows.Forms.WebBrowser.get_Document()
     at InteriorHealth.EmbeddedBrowser.frmMain.CardRead(String strData) in E:\Develop\TestProject\frmMain.cs:line 265
     at MyTest.frmMain.prtCardReader_DataReceived(Object sender, SerialDataReceivedEventArgs e) in E:\Develop\TestProject\frmMain.cs:line 355
  </code></pre>
  
  <p>The test machine is running IE6.  Although I'm not sure, I'm speculating that the difference in IE versions may be the reason for the error.  Does this sound right?  How do I work around this?</p>
  
  <p>Line 265 of frmMain.cs is:</p>
  
  <pre><code> this.webKiosk.Document.InvokeScript(ConfigurationState.CardReader.Error.FireJavaScriptMethod);
  </code></pre>
  
  <p>Line 355 of frmMain.cs is:</p>
  
  <pre><code>CardRead(strCardData_m);
  </code></pre>
  
  <p>I think the exception is being thrown by the Document property call on the WebBrowser object.</p>