Quantcast
Channel: NAV Three Tier — mibuso.com
Viewing all articles
Browse latest Browse all 10032

Problem. SelectSingleNode('SomeNode') returns a variable of type "nodelist". Not node.

$
0
0
Hi

I have had several occurences of a very peculiar error. It happens in various versions of Dynamics NAV 2013 and up.

What happens is as follows:

Variable: CurrNode - XmlNode
CurrNode := xmlDoc.SelectSingleNode('error');
CurrNode := CurrNode.SelectSingleNode('message');
ERROR(CurrNode.InnerText);

When the above code is executed I get the error Message:
A call to System.Xml.XPathNodeList.SelectSingleNode failed.... blah blah blah...

The error occurs on this line:
CurrNode := CurrNode.SelectSingleNode('message');

That is very odd. Seeing as CurrNode is defined as:
System.Xml.XmlNode.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Which is NOT a nodelist. I then run the debugger on the above code and what happens now is that CurrNode is no longer a variable of type XmlNode .. it has been changed to XmlNodeList which shouldn't technically be possible. But never the less that is what happens.

Has anyone else come across this problem ?

In one instance it was solved by running a windows update on the machine where the code failed. But in other cases I have had to change the code to:
CurrNodeList := xmlDoc.GetElementsByTagName('error');
CurrNode := CurrNodeList.Item(0);

Which works...

This has me stomped and instead of rewriting the code to replace every SelectSingleNode to GetElementsByTagName I would much rather find out what exactly is causing this and find out how to resolve it.

Viewing all articles
Browse latest Browse all 10032

Trending Articles