{"record":{"id":"5a71bd3fb2272af8","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedattribute-reader-localname-5a71bd","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedAttribute, reader.LocalName, AnnotationXmlConstants.Elements.Resource)","messagePattern":"SR\\.Format\\(SR\\.UnexpectedAttribute, reader\\.LocalName, AnnotationXmlConstants\\.Elements\\.Resource\\)","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationResource.cs","lineNumber":455,"sourceCode":"\n                // Skip null values - they will be treated the same as if\n                // they weren't specified at all\n                if (value == null)\n                    continue;\n\n                switch (reader.LocalName)\n                {\n                    case AnnotationXmlConstants.Attributes.Id:\n                        tempId = XmlConvert.ToGuid(value);\n                        break;\n\n                    case AnnotationXmlConstants.Attributes.ResourceName:\n                        _name = value;\n                        break;\n\n                    default:\n                        if (!Annotation.IsNamespaceDeclaration(reader))\n                            throw new XmlException(SR.Format(SR.UnexpectedAttribute, reader.LocalName, AnnotationXmlConstants.Elements.Resource));\n                        break;\n                }\n            }\n\n            if (Guid.Empty.Equals(tempId))\n            {\n                throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.Id, AnnotationXmlConstants.Elements.Resource));\n            }\n\n            _id = tempId;\n\n            // Name attribute is optional, so no need to check it\n\n            // Move back to the parent \"Resource\" element\n            reader.MoveToContent();\n        }\n\n        /// <summary>","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationResource.cs#L437-L473","documentation":"AnnotationResource.ReadAttributes throws XmlException when a <Resource> element carries an attribute whose local name is not recognized (only Id and Name are allowed) and the attribute is not a namespace declaration. This enforces the annotations schema during deserialization via XmlStreamStore.","triggerScenarios":"Loading an annotation XML stream where a <Resource> element has an unknown attribute, e.g. <Resource Id=\"...\" Type=\"foo\">, that is also not a namespace declaration (not in the xmlns family).","commonSituations":"Annotation XML extended by other applications with extra attributes; schema drift between store versions; hand-edited annotation files; round-tripping annotations through systems that add metadata attributes.","solutions":["Remove unknown attributes from <Resource> elements, keeping only Id and Name.","If extra metadata is needed, encode it as child Cargo/Content elements per the schema instead of attributes.","Identify which tool wrote the extra attributes and fix its serializer.","Preprocess/normalize annotation XML files before loading them into XmlStreamStore."],"exampleFix":"// before\n<Resource Id=\"6a1f...\" Name=\"note\" Type=\"text\">\n// after\n<Resource Id=\"6a1f...\" Name=\"note\">","handlingStrategy":"try-catch","validationCode":"var allowed = new[] { \"Id\", \"Name\" };\nforeach (var a in resourceEl.Attributes())\n    if (!allowed.Contains(a.Name.LocalName) && !a.IsNamespaceDeclaration)\n        throw new InvalidDataException($\"Unexpected attribute {a.Name.LocalName}\");","typeGuard":"bool HasOnlyKnownAttributes(XElement r) =>\n    r.Attributes().All(a =>\n        a.IsNamespaceDeclaration || a.Name.LocalName is \"Id\" or \"Name\");","tryCatchPattern":"try { store = new XmlStreamStore(stream); }\ncatch (XmlException ex) { log(ex); sanitizeAnnotationFile(path); reload(); }","preventionTips":["Store extra metadata as Cargo/Content child elements, not Resource attributes.","Check which external tools write to the annotation stream and constrain their schema.","Normalize/sanitize annotation XML before passing it to XmlStreamStore."],"tags":["wpf","annotations","xml","attributes"],"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"}