2011-04-07 85 views
2

正在执行使用WatiN的自动化。使用几个并发线程来测试应用程序。很少线程失败并且日志报告/堆栈跟踪显示以下内容。System.InvalidCastException:指定的转换无效

System.InvalidCastException: Specified cast is not valid. 
    at SHDocVw.IWebBrowser2.get_HWND() 
    at WatiN.Core.Native.InternetExplorer.IEBrowser.get_hWnd() 
    at WatiN.Core.Browser.get_hWnd() 
    at WatiN.Core.DomContainer.StartDialogWatcher() 
    at WatiN.Core.IE.CreateNewIEAndGoToUri(Uri uri, IDialogHandler logonDialogHandler, Boolean createInNewProcess) 
    at WatiN.Core.IE..ctor(Boolean createInNewProcess) 
    at Core.BaseWatinTestWrapper.Run() 

在此之后的异常有被提出,即

System.Runtime.InteropServices.COMException Retrieving the COM class factory for component with CLSID {0002DF01-0000-0000-C000-000000000046} failed due to the following error: 80080005. 

请提供一些帮助其他异常。提前致谢。

+0

自从我们切换到64位计算机后,我们也遇到了这个错误。我们的测试已经在正确的公寓状态下运行。 – Lodewijk 2011-10-05 12:32:52

+0

窗口句柄在COM互操作中很困难,它们在64位操作系统上是64位值。将主项目的Platform目标更改为x86。 – 2011-11-03 06:01:10

回答

0

如果我没有记错,华廷明确是单线程[STApartment] - http://watin.org/documentation/sta-apartmentstate/ 如果你想有这样的测试,我相信你需要在操作系统级别的独立的进程。 我无法确定你是否会碰到这个需求,但我建议单个浏览器(和它的后代windows/processessess)单个实例。另外,可能还有另外一个hickup - WatiN使用浏览器的内部连接到IE,但如果在这个过程中有任何与Windows /用户会话相关的活动,这可能会带来额外的混乱。

2

我也在使用几个线程,并得到相同的错误。使你的主要方法[MTAThread]。这为我解决了这个问题。

相关问题