Cannot use MSXML2 objects in Visual Studio 2010

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have several VBA programs using MSXML2 objects; most run in Excel. A general example is:

Dim objQuery As MSXML2.XMLHTTP60<br/>
Dim xmlResponse As MSXML2.DOMDocument60<br/>
Dim xNodeList As MSXML2.IXMLDOMNodeList<br/>
Dim xNode As MSXML2.IXMLDOMNode
Set objQuery = New MSXML2.XMLHTTP60<br/>
objQuery.Open "GET", urlComplete, False<br/>
objQuery.send<br/>
Set xmlResponse = objQuery.responseXML<br/>
Select Case objQuery.Status<br/>
Case 400...<br/>
Case 200<br/>
cmpDept = xmlResponse.SelectSingleNode("company/division/departmentId").Text<br/>
cmpBuilding = xmlResponse.SelectSingleNode("company/division/buildingId").Text...
Set xNodeList = xmlResponse.SelectNodes("execs/exec/bio")<br/>
For Each xNode In xNodeList<br/>
execUniv = xNode.SelectSingleNode("university").Text<br/>
execDegree = xNode.SelectSingleNode("degree").Text<br/>
Next
Everything works fine in VBA. I cannot get this to work in Visual Studio 2010, however (Visual Basic 2010 Express). There are no compile errors, but the MSXML objects are not fully instantiated. When I get to the cmpDept= statement, I get
the following error message:
A first chance exception of type System.NullReferenceException occurred in Appl.exe
If, in the immediate window, I enter

?xmlResponse.baseName
The response is:
The embedded interop type baseName does not contain a definition for MSXML2.DOMDocument60 since it was not used in the compiled assembly. Consider casting to object or changing the Embed Interop Types property to true.
Embed Interop Types were already set to true. Actually, setting them to false seemed to work a little bit better, but I got different errors. Ive tried casting the objects to other types; no joy.
Looking at the Locals window, it seems as if only part of the objects are defined. The child nodes are not. Here are some tests from the immediate window:

?objQuery.GetType<br/>
{Name = "XMLHTTP60Class" FullName = "MSXML2.XMLHTTP60Class"}<br/>
System.RuntimeType: {Name = "XMLHTTP60Class" FullName = "MSXML2.XMLHTTP60Class"}

?xmlresponse.GetType<br/>
{Name = "__ComObject" FullName = "System.__ComObject"}<br/>
System.RuntimeType: {Name = "__ComObject" FullName = "System.__ComObject"}
xmlresponse should be MSXML2.DOMDocument60Class. Any ideas of how to get this code to work in Visual Studio?





View the full article
 
Back
Top