Skip to content

XNodeReader.GetAttribute(int) handling of invalid indices #26551

@krwq

Description

@krwq

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).

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 6Issues and PRs for the .NET 6 releasebreaking-changeIndicates a .NET Core breaking change

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions