dotnet/wpf · error
SR.ParserFilterXmlReaderNoIndexAttributeAccess
Error message
SR.ParserFilterXmlReaderNoIndexAttributeAccess
What it means
FilteredXmlReader wraps an XmlReader during XAML parsing to filter uid/namespace attributes. It deliberately forbids index-based attribute access because indexes shift after filtering; GetAttribute(int) always throws InvalidOperationException to force name-based access instead.
Solutions
- Rewrite attribute access to use GetAttribute(string localName) or GetAttribute(string name, string ns)
- Use MoveToAttribute(string) / MoveToFirstAttribute + reader indexer by name instead of indexes
- Obtain the underlying inner reader if index access is truly required (and accept unfiltered data)
- Avoid wrapping FilteredXmlReader in code that strictly requires index-based attribute APIs
Example fix
// before
string v = filteredReader.GetAttribute(0); // throws
// after
string v = filteredReader.GetAttribute("Uid") ?? filteredReader.GetAttribute("x:Uid"); Defensive patterns
Strategy: type-guard
Validate before calling
if (reader is FilteredXmlReader) return (reader as FilteredXmlReader).GetAttribute(name); else return reader.GetAttribute(index);
Type guard
static bool SupportsIndexAttributeAccess(XmlReader r) => !(r is FilteredXmlReader);
Try / catch
try { v = reader.GetAttribute(i); } catch (InvalidOperationException ex) when (ex.Message.Contains("Index") || ex.Message.Contains("attribute")) { v = reader.GetAttribute(attributeNames[i]); } Prevention
- Never index into a FilteredXmlReader; use name-based GetAttribute/MoveToAttribute
- Build attribute-name lists from MoveToFirstAttribute/MoveToNextAttribute traversal
- Keep FilteredXmlReader details out of generic XmlReader utilities
When it happens
Trigger: Any call to the filtered reader's GetAttribute(attributeIndex) overload — e.g. generic XmlReader-processing code that iterates attributes by index over a FilteredXmlReader instance.
Common situations: Plugging FilteredXmlReader into frameworks/tools that assume standard XmlReader index semantics (XmlReadMode internals, diagnostics readers, custom parser extensions); upgrading code paths that used to receive a raw XmlReader.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Animation_NoTextChildren
- Animation_NoTextChildren
- SR.Animation_NoTextChildren
- SR.Animation_NoTextChildren
- SR.Animation_NoTextChildren
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d99e8535a7f1fea6.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/FilteredXmlReader.cs:122
{
return GetAttribute( localName, namespaceUri ); // Defined elsewhere in this file.
}
}
#endregion Public Properties
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
#region Public Methods
public override string GetAttribute( int attributeIndex )
{
// Index-based acccess are not allowed. See remark at top of this file.
throw new InvalidOperationException(
SR.ParserFilterXmlReaderNoIndexAttributeAccess);
}
public override string GetAttribute( string attributeName )
{
if( attributeName == uidQualifiedName )
{
return null; // ...these aren't the attributes you're looking for...
}
else
{
return base.GetAttribute( attributeName );
}
}
public override string GetAttribute( string localName, string namespaceUri )
{
if( localName == uidLocalName && View on GitHub (pinned to 81131a70a4)