WebBrowser Issue with Late Bind object/property names

5

There are issue with using WebBrowser late bind calls related to object/property names generation.

For example:

WebBrowser1.Document.DomDocument.Forms.Myform.mycontrol.Value = "test"

will fail with more than one instance of the WebBrowser control

what actually happen is that mycontrol object become Mycontrol and compiled vb.net application will fail with error

Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND)) at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack) at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack) at Execute() in C:\Projects\WebBrowser\SampleCall.vb:line 16

Is there are any solutions for this issue?

Same code will work with vb6 app with multiple WebBrowser controls

Edit: This code is comipled with: Option Strict Off

vb.net
browser
late-binding
asked on Stack Overflow Aug 13, 2010 by user • edited Aug 17, 2010 by user

2 Answers

2

@bugtussle

Next assignments will work:

WebBrowser1.Document.Forms("Myform").Children("mycontrol").InnerText = "test"
WebBrowser1.Document.DomDocument.Forms("Myform").all("mycontrol").Value = "test"
WebBrowser1.Document.DomDocument.Forms.Myform.all.mycontrol.Value = "test"

The problem with this approach that is required to change and retest a lot of code

If you take a look into Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet method using reflector utility, you can find that BindingFlags.IgnoreCase flag is used in binder.InvokeMember call.

I do undestant that this call is done through COM, and was reading somewhere that COM interop is using one version of name in a lookup table. Like if parameter name was initially entered into that table as "MyControl" than this version will be used, not "mycontrol". I think because of that later on InvokeMember is failing to find correct member.

answered on Stack Overflow Aug 19, 2010 by user
0

Try setting the value a different way:
WebBrowser1.Document.Forms("Myform").children("mycontrol").Value = "test"

answered on Stack Overflow Aug 18, 2010 by bugtussle

User contributions licensed under CC BY-SA 3.0