{"record":{"id":"9c67df76d86485c7","repo":"dotnet/wpf","slug":"sr-format-sr-requiredattributemissing-annotationxmlconstants-9c67df","errorCode":null,"errorMessage":"SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.ItemValue, AnnotationXmlConstants.Elements.Item)","messagePattern":"SR\\.Format\\(SR\\.RequiredAttributeMissing, AnnotationXmlConstants\\.Attributes\\.ItemValue, AnnotationXmlConstants\\.Elements\\.Item\\)","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPartList.cs","lineNumber":251,"sourceCode":"                                            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                                    {\n                                        // Should not contain any content, only attributes\n                                        throw new XmlException(SR.Format(SR.InvalidXmlContent, AnnotationXmlConstants.Elements.Item));\n                                    }\n                                    else","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPartList.cs#L233-L269","documentation":"Each <Item> element must also carry a Value attribute; when it is absent, ReadXml throws XmlException(SR.RequiredAttributeMissing, \"Value\", \"Item\"). Both attributes are mandatory because the Item encodes one name/value pair of the locator part.","triggerScenarios":"Deserializing an annotations stream where an Item element has only a Name attribute, e.g. <Item Name=\"k\"/> (perhaps intended as an empty value but written without Value).","commonSituations":"Custom annotation writers skipping empty-string values instead of serializing Value=\"\"; hand-edited files; template XML missing attributes.","solutions":["Add the Value attribute to every Item element; use Value=\"\" for empty values.","Fix the writer so it always emits both Name and Value, even when the value is empty.","Pre-validate the annotation XML before passing it to the store."],"exampleFix":"// before\n<Item Name=\"key\"/>\n// after\n<Item Name=\"key\" Value=\"\"/>","handlingStrategy":"validation","validationCode":"foreach (var item in doc.Descendants(\"Item\"))\n    if ((string?)item.Attribute(\"Value\") is null)\n        throw new InvalidDataException(\"Item is missing required Value attribute\");","typeGuard":null,"tryCatchPattern":"try { LoadAnnotations(stream); }\ncatch (XmlException ex) when (ex.Message.Contains(\"Value\")) { /* repair the Item elements or skip the file */ }","preventionTips":["Always serialize Value, even for empty strings (Value=\"\").","Fix writers that skip null/empty values instead of writing empty attributes.","Include round-trip tests that cover empty name/value pairs."],"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-21T21:30:21.729Z"}