{"record":{"id":"252a6daeffaea594","repo":"dotnet/wpf","slug":"sr-format-sr-invalidxmlcontent-annotationxmlconstants-252a6d","errorCode":null,"errorMessage":"SR.Format(SR.InvalidXmlContent, AnnotationXmlConstants.Elements.Item)","messagePattern":"SR\\.Format\\(SR\\.InvalidXmlContent, AnnotationXmlConstants\\.Elements\\.Item\\)","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPartList.cs","lineNumber":267,"sourceCode":"                                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\n                                    {\n                                        reader.Read(); // Read the end of the Item tag\n                                    }\n                                }\n                            }\n                            else\n                            {\n                                // The locator part contains data other than just \"Item\" tags\n                                throw new XmlException(SR.Format(SR.InvalidXmlContent, part.PartType.Name));\n                            }\n                        }\n                    }\n\n                    _parts.Add(part);\n\n                    reader.Read();  // Read the ContentLocatorPart element                ","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPartList.cs#L249-L285","documentation":"Item elements must be attribute-only; they may not contain child content. If an Item element is non-empty and the reader lands on anything other than the Item EndElement, ReadXml throws XmlException(SR.InvalidXmlContent, \"Item\").","triggerScenarios":"Deserializing annotations where an Item has children or inner text, e.g. <Item Name=\"k\" Value=\"v\"><Extra/></Item> or <Item Name=\"k\" Value=\"v\">text</Item>.","commonSituations":"Tools that serialize key/value pairs as nested elements; hand-edited annotation files; merging markup from other formats into annotation XML.","solutions":["Remove all child nodes from Item elements; express all data via Name/Value attributes.","Regenerate the annotation stream with the standard WPF annotation writer.","Validate the XML structure before loading."],"exampleFix":"// before\n<Item Name=\"k\" Value=\"v\"><Extra>x</Extra></Item>\n// after\n<Item Name=\"k\" Value=\"v\"/>","handlingStrategy":"validation","validationCode":"foreach (var item in doc.Descendants(\"Item\"))\n    if (!item.IsEmpty && item.Nodes().Any())\n        throw new InvalidDataException(\"Item must not contain child content\");","typeGuard":null,"tryCatchPattern":"try { LoadAnnotations(stream); }\ncatch (XmlException ex) when (ex.Message.Contains(\"Item\")) { /* strip Item children and retry, or reject the file */ }","preventionTips":["Treat Item as attribute-only; never nest elements or text inside it.","Sanitize externally produced annotation XML before loading.","Document the annotation XML contract for any tool that generates these files."],"tags":["wpf","annotations","xml"],"backgroundTag":"xml-parse-error","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"}