WebBrowser文档转换无效

我的页面上有一个WebBrowser控件。 要在浏览器控件中显示的页面上激活一些javascript,我调用this.myBrowser.Document.InvokeScript(“Test”);

这适用于我的开发盒与IE7,但在一个单独的测试机器上,我收到以下错误:

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 

测试机器正在运行IE6。 虽然我不确定,但我猜测IE版本的差异可能是错误的原因。 这听起来不错吗? 我该如何解决这个问题?

frmMain.cs的第265行是:

  this.webKiosk.Document.InvokeScript(ConfigurationState.CardReader.Error.FireJavaScriptMethod); 

frmMain.cs的第355行是:

 CardRead(strCardData_m); 

我认为WebBrowser对象上的Document属性调用抛出了exception。

弄清楚了。 我的调用是从串行端口数据接收事件调用的,该事件不在主GUI线程上执行。 我使用this.Invoke()方法调用来获取我的代码在主GUI线程上执行,现在一切都很好!