{"record":{"id":"1a487e4e9cafa2b7","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedattribute-reader-localname-1a487e","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedAttribute, reader.LocalName, AnnotationXmlConstants.Elements.Item)","messagePattern":"SR\\.Format\\(SR\\.UnexpectedAttribute, reader\\.LocalName, AnnotationXmlConstants\\.Elements\\.Item\\)","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPartList.cs","lineNumber":240,"sourceCode":"                        {\n                            if (AnnotationXmlConstants.Elements.Item == reader.LocalName && reader.NamespaceURI == AnnotationXmlConstants.Namespaces.CoreSchemaNamespace)\n                            {\n                                string name = null;\n                                string value = null;\n\n                                while (reader.MoveToNextAttribute())\n                                {\n                                    switch (reader.LocalName)\n                                    {\n                                        case AnnotationXmlConstants.Attributes.ItemName:\n                                            name = reader.Value;\n                                            break;\n                                        case AnnotationXmlConstants.Attributes.ItemValue:\n                                            value = reader.Value;\n                                            break;\n                                        default:\n                                            if (!Annotation.IsNamespaceDeclaration(reader))\n                                                throw new XmlException(SR.Format(SR.UnexpectedAttribute, reader.LocalName, AnnotationXmlConstants.Elements.Item));\n                                            break;\n                                    }\n                                }\n\n                                if (name == null)\n                                {\n                                    throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.ItemName, AnnotationXmlConstants.Elements.Item));\n                                }\n                                if (value == null)\n                                {\n                                    throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.ItemValue, AnnotationXmlConstants.Elements.Item));\n                                }\n\n                                reader.MoveToContent();\n\n                                part.NameValuePairs.Add(name, value);\n\n                                bool isEmpty = reader.IsEmptyElement;","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPartList.cs#L222-L258","documentation":"When reading an <Item> element inside a ContentLocatorPart, only the expected Name/Value attributes (and namespace declarations) are allowed. Any other attribute produces XmlException(SR.UnexpectedAttribute, attributeName, \"Item\"). This enforces the strict annotation XML format.","triggerScenarios":"Deserializing an annotations stream where an Item element carries an unknown attribute, e.g. <Item Name=\"k\" Value=\"v\" Extra=\"x\"/>.","commonSituations":"Annotation files edited or generated by external tools adding metadata attributes; schema evolution between framework versions; copy-paste of similar markup from other XML formats.","solutions":["Remove unknown attributes from Item elements, keeping only Name and Value (plus xmlns declarations).","Regenerate the annotation stream with a compatible writer.","Pre-validate the XML against the annotation schema before loading."],"exampleFix":"// before\n<Item Name=\"key\" Value=\"val\" Extra=\"oops\"/>\n// after\n<Item Name=\"key\" Value=\"val\"/>","handlingStrategy":"validation","validationCode":"foreach (var item in doc.Descendants(\"Item\"))\n    foreach (var attr in item.Attributes())\n        if (attr.Name.LocalName is not (\"Name\" or \"Value\") && !attr.IsNamespaceDeclaration)\n            throw new InvalidDataException($\"Unexpected attribute {attr.Name.LocalName} on Item\");","typeGuard":null,"tryCatchPattern":"try { LoadAnnotations(stream); }\ncatch (XmlException ex) when (ex.Message.Contains(\"attribute\")) { /* quarantine the bad annotation file and log */ }","preventionTips":["Emit only Name and Value attributes on Item elements when writing annotations.","Strip tool-specific attributes before feeding XML into the annotation store.","Add schema validation to your annotation import pipeline."],"tags":["wpf","annotations","xml","schema-validation"],"backgroundTag":"schema-validation-failed","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"}