{"record":{"id":"f3ccfc271338dde9","repo":"dotnet/wpf","slug":"sr-format-sr-invalidxmlcontent-part-parttype-name","errorCode":null,"errorMessage":"SR.Format(SR.InvalidXmlContent, part.PartType.Name)","messagePattern":"SR\\.Format\\(SR\\.InvalidXmlContent, part\\.PartType\\.Name\\)","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPartList.cs","lineNumber":278,"sourceCode":"                                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                \n                }\n            }\n\n            reader.Read(); // Reads the end of the \"ContentLocator\" element (or whole element if empty)\n        }\n\n        #endregion IXmlSerializable Implementation\n\n        #endregion Public Methods\n\n        //------------------------------------------------------","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPartList.cs#L260-L296","documentation":"Inside a ContentLocatorPart, only <Item> children are permitted. If the reader encounters any other child element (or stray content), ReadXml throws XmlException(SR.InvalidXmlContent, part.PartType.Name), naming the offending locator part's type.","triggerScenarios":"Deserializing a ContentLocatorPart element whose children include elements other than Item, e.g. <MyPart xmlns=\"...\"><OtherThing/></MyPart>.","commonSituations":"Newer or third-party annotation producers adding extension elements; hand-edited files; version drift where a producer wrote richer parts than this reader understands.","solutions":["Ensure ContentLocatorPart elements contain only Item children.","Align the producing tool's schema with the WPF annotation format, or strip unknown children before loading.","Regenerate the annotation store from the original application."],"exampleFix":"// before\n<MyPart xmlns=\"...\"><OtherThing/></MyPart>\n// after\n<MyPart xmlns=\"...\"><Item Name=\"k\" Value=\"v\"/></MyPart>","handlingStrategy":"validation","validationCode":"foreach (var part in doc.Descendants().Where(e => e.Name.Namespace == annotationNs && e.Name.LocalName != \"Item\" && e.Name.LocalName != \"ContentLocator\"))\n    if (part.Elements().Any(c => c.Name.LocalName != \"Item\"))\n        throw new InvalidDataException($\"Locator part {part.Name.LocalName} has non-Item children\");","typeGuard":null,"tryCatchPattern":"try { LoadAnnotations(stream); }\ncatch (XmlException ex) when (ex.Message.Contains(\"InvalidXmlContent\")) { /* drop unknown locator-part children and re-import */ }","preventionTips":["Only ever write Item children inside ContentLocatorPart elements.","Align producers and consumers on one annotation schema version.","Pre-validate third-party annotation files before load."],"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"}