We have an ActiveX component that displays a Web page in an Internet Explorer window via SHDocVw. In the DocumentComplete event handler, we attempt to retrieve the value from one of the controls on the page. We know the control is on the page (it's visible via a Fiddler trace).
It's at this point that things get wonky. We receive the following error message at runtime:
Error Message:
Public member 'elements' on type 'DBNull' not found.
Error Routine Location:
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(String& MemberName, Boolean ReportErrors)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at Foo.AddinModule.m_internetExplorer_DownloadComplete(Object pDisp, Object& url)
Error Source:
Microsoft.VisualBasic
Error Site Location:
System.Reflection.MemberInfo[] GetMembers(System.String ByRef, Boolean)
The offending line of code is this one:
Me.IEInstance.Document.forms("frmRedirect").elements("redirectData").Value = outlookXML.OuterXml
So, essentially, Me.IEInstance.Document.forms("frmRedirect")
is evaluating to DBNull
.
We've eliminated case sensitivity issues. Tried moving the control around within the page, and verified that the HTML is well-formed. I have no idea why this is occurring. A sample of the generated HTML is below.
Can anyone suggest a cause and a possible resolution for this issue? I'm entertaining any and all suggestions at this point.
HTML Sample
<form id='frmRedirect' name='frmRedirect' action='pw_outlook/choosecontacts.aspx' method='POST'>
<input type='hidden' name='redirectData'>
</form>
UPDATE 3/28/2012
We have determined that the code works fine under certain configurations. Then, mysteriously, it will succeed for some users if you change the code as follows:
Me.IEInstance.Document.forms("frmRedirect").Elements("redirectData").Value = outlookXML.OuterXml
^
^
That is, if you simply change the case of Elements
. This, to me, smacks of a case sensitivity issue during a COM vtable lookup, but the mystery is that it doesn't occur for everyone. Just some users.
Also, please note that the form that is returned by .forms("frmRedirect")
is a valid object; however, it doesn't appear to have an elements()
method.