XNodeReader.GetAttribute(int) handling of invalid indices
XNodeReader is an internal class but accessible through XmlReader class when using XNode.CreateReader.
All XmlReader implementations except XNodeReader throw ArgumentOutOfRangeException on invalid indices in the GetAttribute(int) method. Documentation of XmlReader says that ArgumentOutOfRange is the expected behavior. This issue has been addressed
Version introduced
.NET 6.0
Old behavior
XNodeReader.GetAttribute(int) returned null for invalid indices.
New behavior
XNodeReader.GetAttribute(int) throws ArgumentOutOfRangeException.
Reason for change
XmlReader.GetAttribute(int) is well documented and XNodeReader is not behaving as document and also inconsistently with other XmlReader implementations.
Recommended action
Use XmlReader.AttributeCount to retrieve number of attributes in the current node and always pass value in 0..XmlReader.AttributeCount-1 range to XmlReader.GetAttribute(int).
XNodeReader.GetAttribute(int) handling of invalid indices
XNodeReader is an internal class but accessible through XmlReader class when using
XNode.CreateReader.All XmlReader implementations except XNodeReader throw ArgumentOutOfRangeException on invalid indices in the
GetAttribute(int)method. Documentation of XmlReader says that ArgumentOutOfRange is the expected behavior. This issue has been addressedVersion introduced
.NET 6.0
Old behavior
XNodeReader.GetAttribute(int)returned null for invalid indices.New behavior
XNodeReader.GetAttribute(int)throws ArgumentOutOfRangeException.Reason for change
XmlReader.GetAttribute(int)is well documented andXNodeReaderis not behaving as document and also inconsistently with otherXmlReaderimplementations.Recommended action
Use
XmlReader.AttributeCountto retrieve number of attributes in the current node and always pass value in0..XmlReader.AttributeCount-1range toXmlReader.GetAttribute(int).