My team has a bunch of WatiN test suites which run automatically by our TeamCity server. We recently switched all of our build agents to 64 bit and I also switched our WatiN tests to use NUnit in x64 mode. Watin has always given us infrequent test failures because of failed Interop calls to the IE browser or for other reasons but these have always been quite rare. Since switching everything to 64 bit, almost every run of any of our test suites fails with the following Exception:
Test(s) failed. System.InvalidCastException : Specified cast is not valid.
at SHDocVw.IWebBrowser2.get_HWND()
at WatiN.Core.Native.InternetExplorer.IEBrowser.get_hWnd()
at WatiN.Core.DomContainer.StartDialogWatcher()
at WatiN.Core.IE.CreateNewIEAndGoToUri(Uri uri, IDialogHandler logonDialogHandler, Boolean createInNewProcess)
...
I found a related question where a WatiN user is seeing the same exception but it is because she is attempting multi-threading. We are not doing any such thing, infact we are using the correct thread state apartment as suggested by the WatiN documentation. I did notice in the question though that someone had commented saying it might be because x86 vs. x64 mode.
How can I avoid this error causing my tests to frequently fail?
If it is simply a matter of switching back to 32 bit mode, I can handle that but I wanted to know for sure that there is no better solution. Thanks.
UPDATE:
After leaving the jobs as using 64 bit NUnit runner for about 5+ runs of the test suites, they failed every time except once with this same error. We switched them back to 32 bit and have had 10+ successful runs since. I guess the temporary fix for now is use a 32 bit NUnit runner although I am still looking for a reason this happens or a solution that would allows us to switch back to x64.