2

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.

eldarerathis
  • 35,455
  • 10
  • 90
  • 93
GTK
  • 21
  • 2
  • We're getting this error as well since we switched to 64bit computers. Our tests already run in the correct apartment state. – Lodewijk Oct 05 '11 at 12:32
  • Window handles are difficult in COM interop, they are 64-bit values on a 64-bit operating system. Change the main project's Platform target to x86. – Hans Passant Nov 03 '11 at 06:01

2 Answers2

2

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

0

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.

PMD
  • 64
  • 3