XNodeReader.GetAttribute behavior for invalid index

XNodeReader is an internal class, but it's accessible through the XmlReader class if you call XNode.CreateReader. All XmlReader implementations except XNodeReader threw an ArgumentOutOfRangeException for an invalid index in the GetAttribute(Int32) method. With this change, XNodeReader.GetAttribute(int) now also throws an ArgumentOutOfRangeException for an invalid index.

Old behavior

XNodeReader.GetAttribute(int) returned null if the index was invalid.

New behavior

XNodeReader.GetAttribute(int) throws an ArgumentOutOfRangeException if the index is invalid.

Version introduced

.NET 6

Type of breaking change

This change can affect source compatibility.

Reason for change

XmlReader.GetAttribute(int) is well documented, and XNodeReader was not behaving as documented. It's behavior for invalid indices was also inconsistent with other XmlReader implementations.

To avoid an invalid index:

Affected APIs