{"record":{"id":"d99e8535a7f1fea6","repo":"dotnet/wpf","slug":"sr-parserfilterxmlreadernoindexattributeaccess","errorCode":null,"errorMessage":"SR.ParserFilterXmlReaderNoIndexAttributeAccess","messagePattern":"SR\\.ParserFilterXmlReaderNoIndexAttributeAccess","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/FilteredXmlReader.cs","lineNumber":122,"sourceCode":"        {\n            return GetAttribute( localName, namespaceUri ); // Defined elsewhere in this file.\n        }\n    }\n\n    #endregion Public Properties\n    \n    //------------------------------------------------------\n    //\n    //  Public Methods\n    //\n    //------------------------------------------------------\n\n    #region Public Methods\n\n    public override string GetAttribute( int attributeIndex )\n    {\n        // Index-based acccess are not allowed.  See remark at top of this file.\n        throw new InvalidOperationException(\n            SR.ParserFilterXmlReaderNoIndexAttributeAccess);\n    }\n\n    public override string GetAttribute( string attributeName )\n    {\n        if( attributeName == uidQualifiedName )\n        {\n            return null;  // ...these aren't the attributes you're looking for...\n        }\n        else\n        {\n            return base.GetAttribute( attributeName );\n        }\n    }\n    \n    public override string GetAttribute( string localName, string namespaceUri )\n    {\n        if( localName == uidLocalName && ","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/FilteredXmlReader.cs#L104-L140","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nstring v = filteredReader.GetAttribute(0); // throws\n// after\nstring v = filteredReader.GetAttribute(\"Uid\") ?? filteredReader.GetAttribute(\"x:Uid\");","handlingStrategy":"type-guard","validationCode":"if (reader is FilteredXmlReader) return (reader as FilteredXmlReader).GetAttribute(name); else return reader.GetAttribute(index);","typeGuard":"static bool SupportsIndexAttributeAccess(XmlReader r) => !(r is FilteredXmlReader);","tryCatchPattern":"try { v = reader.GetAttribute(i); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Index\") || ex.Message.Contains(\"attribute\")) { v = reader.GetAttribute(attributeNames[i]); }","preventionTips":["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"],"tags":["xml","xaml","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}