I’m using a System.Window.Controls Webbrowser (WPF) which is throwing up a few anomolies here and there.
Normally if I want to get access to the webbrowser document in Winforms and click an element I would use
HtmlDocument document = webNav.webBrowser1.Document;
document.GetElementById("id_of_element").InvokeMember("Click");
However, in WPF it throws error Cannot implicitly convert type 'object' to 'System.Windows.Forms.HtmlDocument'. An explicit conversion exists (are you missing a cast?).
I can get around this by using
dynamic document = webNav.webBrowser1.Document;
document.GetElementById("id_of_element").InvokeMember("Click");
Is there a better/preferred method or is this an acceptable use of the dynamic type? (are there any examples of acceptable use of dynamic type?)
Like the error says, you are missing an explicit cast:
Assuming you have
using System.Windows.Forms;at the top of the file (to make the code above shorter).I knew this because of the line,
No use of
dynamicis needed in this instance.