System.InvalidCastException: Specified cast is not valid

橙三吉。 提交于 2019-12-24 05:05:00

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/5584247/system-invalidcastexception-specified-cast-is-not-valid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!