Problem. SelectSingleNode('SomeNode') returns a variable of type "nodelist". Not node.
Verndroid
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
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:
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:
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.
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.
0
Answers
-
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.0
-
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.0 -
Have you tried :
XmlDocReqL.DocumentElement.SelectSingleNode('Error').InnerText;0 -
Hi @Verndroid , did you find any solution for your problema?
thanks0 -
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 329 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
