{"record":{"id":"c8a85ed371c1a888","repo":"dotnet/wpf","slug":"sr-format-sr-invalidxmlcontent-annotationxmlconstants-c8a85e","errorCode":null,"errorMessage":"SR.Format(SR.InvalidXmlContent, AnnotationXmlConstants.Elements.ContentLocator)","messagePattern":"SR\\.Format\\(SR\\.InvalidXmlContent, AnnotationXmlConstants\\.Elements\\.ContentLocator\\)","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPartList.cs","lineNumber":207,"sourceCode":"        {\n            ArgumentNullException.ThrowIfNull(reader);\n\n            // We expect no attributes on a \"ContentLocator\", \n            // so throw using the name of one of the unexpected attributes\n            Annotation.CheckForNonNamespaceAttribute(reader, AnnotationXmlConstants.Elements.ContentLocator);\n\n            if (!reader.IsEmptyElement)\n            {\n                reader.Read();  // Reads the start of the \"ContentLocator\" element\n\n                // ContentLocatorParts cannot write themselves out (see above).  They could read\n                // themselves in but instead of having write code in one place and read \n                // code somewhere else - we keep it together in this class.\n                while (!(AnnotationXmlConstants.Elements.ContentLocator == reader.LocalName && XmlNodeType.EndElement == reader.NodeType))\n                {\n                    if (XmlNodeType.Element != reader.NodeType)\n                    {\n                        throw new XmlException(SR.Format(SR.InvalidXmlContent, AnnotationXmlConstants.Elements.ContentLocator));\n                    }\n\n                    ContentLocatorPart part = new ContentLocatorPart(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI));\n                    \n                    // Read each of the Item elements within the ContentLocatorPart\n                    if (!reader.IsEmptyElement)\n                    {\n                        // We expect no attributes on a locator part tag, \n                        // so throw using the name of one of the unexpected attributes\n                        Annotation.CheckForNonNamespaceAttribute(reader, part.PartType.Name);\n\n                        reader.Read(); // Read the start of the locator part tag\n\n                        while (!(XmlNodeType.EndElement == reader.NodeType && part.PartType.Name == reader.LocalName))\n                        {\n                            if (AnnotationXmlConstants.Elements.Item == reader.LocalName && reader.NamespaceURI == AnnotationXmlConstants.Namespaces.CoreSchemaNamespace)\n                            {\n                                string name = null;","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPartList.cs#L189-L225","documentation":"While reading a ContentLocator element during annotation deserialization, ReadXml expects only Element nodes inside the locator. Any non-element node (text, comments, CDATA, whitespace-only content at a content position) causes XmlException(SR.InvalidXmlContent, \"ContentLocator\"). The reader is also expected to sit on the ContentLocator EndElement when the loop ends.","triggerScenarios":"Deserializing an annotations stream where a <ContentLocator> contains text or unexpected markup, e.g. <ContentLocator>garbage</ContentLocator> or a child that is not a locator part element.","commonSituations":"Hand-edited annotation store files; annotation XML generated by other tools that include whitespace/text nodes or extra elements; corrupted streams; version drift where newer annotations embed unknown content.","solutions":["Fix the annotation XML so ContentLocator contains only well-formed locator-part child elements.","Regenerate the annotation stream from a known-good source instead of hand-editing.","Validate the XML against the annotation schema before passing the stream to the store."],"exampleFix":"// before\n<ContentLocator>some text<Part .../></ContentLocator>\n// after\n<ContentLocator><MyPart xmlns=\"http://schemas.microsoft.com/annotations\"/></ContentLocator>","handlingStrategy":"try-catch","validationCode":"// Before loading: ensure ContentLocator elements contain only element children\nforeach (var locator in doc.Descendants(\"ContentLocator\"))\n    if (locator.Nodes().Any(n => n is XText t && !string.IsNullOrWhiteSpace(t.Value)))\n        throw new InvalidDataException(\"ContentLocator contains non-element content\");","typeGuard":null,"tryCatchPattern":"try { store.LoadAnnotations(stream); }\ncatch (XmlException ex) when (ex.Message.Contains(\"ContentLocator\")) { /* discard or repair the malformed annotation file */ }","preventionTips":["Never hand-edit annotation store files; regenerate them with the app.","Validate annotation XML against the WPF annotation schema before loading.","Keep producer and consumer framework versions aligned."],"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"}