System.InvalidCastException:指定的强制转换无效

发布于 2024-10-31 13:47:29 字数 803 浏览 3 评论 0原文

使用 WatiN 的自动化正在进行中。使用几个并发线程来测试应用程序。很少有线程失败,日志报告/堆栈跟踪显示以下内容。

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.

请提供一些帮助。提前致谢。

Automation using WatiN is being carried out. Using couple of simultaneous threads to test the application. Few threads are failed and log report/stack trace says the following.

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()

Following this exception there is another exception being raised i.e.

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.

Please provide some help. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恋竹姑娘 2024-11-07 13:47:29

我还使用了几个线程并遇到了相同的错误。将您的主要方法设置为 [MTAThread]。这解决了我的问题。

I was also using couple of threads and was getting the same error. Make your main method [MTAThread]. This fixed the problem for me.

节枝 2024-11-07 13:47:29

如果我没记错的话,WatiN 明确是单线程的 [STApartment]
- http://watin.org/documentation/sta-apartmentstate/
如果您希望进行这样的测试,我相信您需要操作系统级别的单独进程。
我无法确定您的方法是否与此要求相冲突,但我建议单个浏览器使用单个实例(及其后代窗口/进程)。

此外,可能还有另一个问题 - WatiN 使用浏览器内部连接到 IE,但如果在此过程中存在任何 Windows/用户会话相关活动,这可能会带来额外的混乱。

If I'm not mistaken, WatiN explicitly is single-threaded [STApartment]
- http://watin.org/documentation/sta-apartmentstate/
If you wish to have such test, I believe you need separate processes in OS-level.
I can't tell for sure does you approach collide with this requirement, yet I'd suggest single instance for single browser (and it's descendent windows / processess).

Also, there might be another hickup - WatiN connects to IE using browser's internals, but if there's any Windows / User Session related activity along the way, this might bring additional confusion.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文