Windows Service Webbrowser object invalid cast exception error
Posted
by Sam Youtsey
on Stack Overflow
See other posts from Stack Overflow
or by Sam Youtsey
Published on 2010-03-01T23:38:25Z
Indexed on
2010/05/06
22:58 UTC
Read the original article
Hit count: 543
Hi all,
I'm having a bit of trouble with a Windows Service webbrowser object. It's attempting to load in values of username and password to a site but keeps failing and throwing the following error:
System.InvalidCastException: Specified cast is not valid.
at System.Windows.Forms.UnsafeNativeMethods.IHTMLDocument2.GetLocation()
at System.Windows.Forms.WebBrowser.get_Document()
at MyWindowsService.MyDataProcessor.login()
The code that I'm using to make this call is:
MyWebBrowser.Document.All["Login"].SetAttribute("Value", username);
MyWebBrowser.Document.All["Password"].SetAttribute("Value", password);
MyWebBrowser.Document.All["submit"].InvokeMember("Click");
Any ideas as to why it keeps failing? Thanks in advance for the help.
© Stack Overflow or respective owner