具有Late Bind对象/属性名称的WebBrowser问题

时间:2010-08-13 07:23:35

标签: vb.net browser late-binding

使用与对象/属性名称生成相关的WebBrowser后期绑定调用存在问题。

例如:

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

将因多个WebBrowser控件实例而失败

实际发生的是 mycontrol 对象变为 Mycontrol ,编译的vb.net应用程序将失败并显示错误

  

未找到会员。 (来自HRESULT的异常:0x80020003(DISP_E_MEMBERNOTFOUND))   在Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o,Type objType,   String name,Object [] args,String [] paramnames,Boolean [] CopyBack)   在Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(对象实例,   Type Type,String MemberName,Object [] Arguments,String [] ArgumentNames,   键入[] TypeArguments,Boolean [] CopyBack)   在C:\ Projects \ WebBrowser \ SampleCall.vb中的Execute():第16行

这个问题有什么解决方案吗?

相同的代码适用于具有多个WebBrowser控件的vb6应用程序

编辑:此代码与以下内容混合:选项严格关闭

2 个答案:

答案 0 :(得分:2)

@bugtussle

下一个作业将起作用:

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"

这种方法需要更改和重新测试大量代码

如果您使用反射器实用程序查看Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet方法,您可以在binder.InvokeMember调用中找到BindingFlags.IgnoreCase标志。

我不知道这个调用是通过COM完成的,并且正在读取COM互操作在查找表中使用一个版本的名称的地方。就像参数名称最初作为“MyControl”输入到该表中一样,将使用此版本,而不是“mycontrol”。我想因为后来InvokeMember未能找到正确的成员。

答案 1 :(得分:0)

尝试以不同的方式设置值:
WebBrowser1.Document.Forms("Myform").children("mycontrol").Value = "test"