System.InvalidCastException:指定的强制转换无效
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还使用了几个线程并遇到了相同的错误。将您的主要方法设置为 [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.
如果我没记错的话,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.