I have a C# WPF application with a web browser control (System.Windows.Controls.WebBrowser) called wB. It is supposed to display a local html file, and some information parsed from it.
I get the a NullReferenceException as it says body is null in the last line (IHTMLElementCollection data = hDoc.body.children as IHTMLElementCollection) with the following code:
wB.Navigate(new Uri(file, UriKind.Absolute));
HTMLDocument hDoc = (HTMLDocumentClass)wB.Document;
IHTMLElementCollection data = hDoc.body.children as IHTMLElementCollection;
If I do
wB.Navigate(new Uri(file, UriKind.Absolute));
HTMLDocument hDoc = (HTMLDocumentClass)wB.Document;
System.Windows.MessageBox.Show("Loc:" + hDoc.url);
IHTMLElementCollection data = hDoc.body.children as IHTMLElementCollection;
Everything works fine. Why is body showing up null in the 1st example, but fine for the second?
Edit1 The method is marked as [STAThread]...so I thought concurrency wouldn't be an issue...