{"record":{"id":"eab38143eb445a37","repo":"dotnet/wpf","slug":"sr-format-sr-requiredattributemissing-annotationxmlconstants-eab381","errorCode":null,"errorMessage":"SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.ItemName, AnnotationXmlConstants.Elements.Item)","messagePattern":"SR\\.Format\\(SR\\.RequiredAttributeMissing, AnnotationXmlConstants\\.Attributes\\.ItemName, AnnotationXmlConstants\\.Elements\\.Item\\)","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPartList.cs","lineNumber":247,"sourceCode":"                                {\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;\n\n                                reader.Read();  // Read the beginning of the complete Item tag\n\n                                if (!isEmpty)\n                                {\n                                    if (!(XmlNodeType.EndElement == reader.NodeType && AnnotationXmlConstants.Elements.Item == reader.LocalName))\n                                    {","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPartList.cs#L229-L265","documentation":"Each <Item> element in a ContentLocatorPart must carry a Name attribute; when it is absent, ReadXml throws XmlException(SR.RequiredAttributeMissing, \"Name\", \"Item\"). Name/Value pairs are the key-value payload of the locator part, so a missing key cannot be represented.","triggerScenarios":"Deserializing an annotations stream where an Item element has only a Value attribute, e.g. <Item Value=\"v\"/>.","commonSituations":"External generators omitting the Name attribute; hand-edited annotation files; bugs in custom annotation writers.","solutions":["Add a Name attribute to every Item element.","Fix the custom writer that produces Item elements so it always emits Name.","Validate the XML against the annotation schema before loading the stream."],"exampleFix":"// before\n<Item Value=\"v\"/>\n// after\n<Item Name=\"key\" Value=\"v\"/>","handlingStrategy":"validation","validationCode":"foreach (var item in doc.Descendants(\"Item\"))\n    if ((string?)item.Attribute(\"Name\") is null)\n        throw new InvalidDataException(\"Item is missing required Name attribute\");","typeGuard":null,"tryCatchPattern":"try { LoadAnnotations(stream); }\ncatch (XmlException ex) when (ex.Message.Contains(\"Name\")) { /* repair the Item elements or skip the file */ }","preventionTips":["Ensure custom annotation writers always emit the Name attribute.","Run schema validation before load in any import path.","Test round-trips (write then read) of your annotation payloads."],"tags":["wpf","annotations","xml","missing-attribute"],"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-22T01:17:13.364Z"}