Using Visual Studio 2010, C# language in a Framework 4.0 project.
Whenever I try to access Document.Window.Frames of the WebBrowser control I get this Exception:
System.Runtime.InteropServices.COMException was unhandled by user code
Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
Source=System.Windows.Forms
ErrorCode=-2147467259
StackTrace:
at System.Windows.Forms.UnsafeNativeMethods.IHTMLFramesCollection2.Item(Object& idOrName)
at System.Windows.Forms.HtmlWindowCollection.get_Item(Int32 index)
at System.Windows.Forms.HtmlWindowCollection.System.Collections.ICollection.CopyTo(Array dest, Int32 index)
at System.Windows.Forms.HtmlWindowCollection.GetEnumerator()
at myBrowserTest.Form1.wb_DocumentCompleted(Object sender, WebBrowserDocumentCompletedEventArgs e) in C:\Documents and Settings\Administrador\Os meus documentos\Visual Studio 2010\Projects\ myBrowserTest\ myBrowserTest \Form1.cs:line 1114
at System.Windows.Forms.WebBrowser.OnDocumentCompleted(WebBrowserDocumentCompletedEventArgs e)
at System.Windows.Forms.WebBrowser.WebBrowserEvent.DocumentComplete(Object pDisp, Object& urlObject)
InnerException:
The line is:
wb.Document.Window.Frames[0].Url.ToString();
But it really doesn't matter. Using anything from Frames gives me that error. Even like this:
foreach (HtmlWindow frame in wb.Document.Window.Frames) { ... }
I know there are frames because Frames.Count gives me a number bigger than 0 and it's the only thing on Frames that doesn't give me an exception.
What can cause this?