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

VerndroidVerndroid Member Posts: 18
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.

Answers

  • DuikmeesterDuikmeester Member Posts: 309
    edited 2016-04-18
    If you check reference source you see that inside SelectSingleNode a NodeList is used. Maybe you have an old version of the .NET Framework which contains a bug that causes to return an empty NodeList inside this function. I would check all the machines running NAV if they are up to date.
  • VerndroidVerndroid Member Posts: 18
    It does not return an empty nodelist. The nodelist is actually as you would expect it to be .. if you had issued a GetElementsByTagName instead of SelectSingleNode.

    Running a windows update does not reveal any updates available for .NET framework.
  • Have you tried :
    XmlDocReqL.DocumentElement.SelectSingleNode('Error').InnerText;
  • NunoSilvaNunoSilva Member Posts: 15
    Hi @Verndroid , did you find any solution for your problema?
    thanks
  • VerndroidVerndroid Member Posts: 18
    Hi @NunoSilva

    Unfortunately no. I have not found a solution. I work around the problem by using GetElementsByTagName instead of SelectSingleNode. Luckily my code is fashioned in such a way that I just have to alter a single Function to use GetElementsByTagName instead of SelectSingleNode so it was not a big deal for me to change it.
Sign In or Register to comment.