{"record":{"id":"ba448002dd2a2fea","repo":"dotnet/wpf","slug":"sr-format-sr-invalidxmlcontent-annotationxmlconstants-ba4480","errorCode":null,"errorMessage":"SR.Format(SR.InvalidXmlContent, AnnotationXmlConstants.Elements.ContentLocatorGroup)","messagePattern":"SR\\.Format\\(SR\\.InvalidXmlContent, AnnotationXmlConstants\\.Elements\\.ContentLocatorGroup\\)","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorGroup.cs","lineNumber":145,"sourceCode":"\n            if (!reader.IsEmptyElement)\n            {\n                reader.Read();  // Reads the start of the \"ContentLocatorGroup\" element\n\n                // Consume everything inside of the ContentLocatorGroup tag.\n                while (!(AnnotationXmlConstants.Elements.ContentLocatorGroup == reader.LocalName && XmlNodeType.EndElement == reader.NodeType))\n                {\n                    // If a child node is a <ContentLocatorBase>, deserialize a ContentLocatorBase\n                    if (AnnotationXmlConstants.Elements.ContentLocator == reader.LocalName)\n                    {\n                        ContentLocator locator = (ContentLocator)AnnotationResource.ListSerializer.Deserialize(reader);                        \n                        _locators.Add(locator);\n                    }\n                    else\n                    {\n                        // The ContentLocatorGroup contains a child that is not a ContentLocatorBase or \n                        // text.  This isn't valid in the schema so we throw.\n                        throw new XmlException(SR.Format(SR.InvalidXmlContent, AnnotationXmlConstants.Elements.ContentLocatorGroup));\n                    }\n                }\n            }\n\n            reader.Read();   // Reads the end of the \"ContentLocatorGroup\" element (or whole element if empty)\n        }\n\n        #endregion IXmlSerializable Implementation\n\n        #endregion Public Methods\n\n        //------------------------------------------------------\n        //\n        //  Public Operators\n        //\n        //------------------------------------------------------\n\n        //------------------------------------------------------","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorGroup.cs#L127-L163","documentation":"ContentLocatorGroup.ReadXml throws this XmlException when the XML reader encounters a child element inside <ContentLocatorGroup> that is not a valid ContentLocatorBase element (ContentLocator or ContentLocatorPart) or text. The file's content violates the annotations XML schema.","triggerScenarios":"Loading an annotation store XML whose ContentLocatorGroup contains unknown/misspelled child elements, elements from a foreign namespace, or hand-edited markup that does not match the schema.","commonSituations":"Manually editing annotation store files; stores produced by third-party or newer/older tooling with extra elements; corrupted or schema-invalid XML persisted by a custom XmlAnnotationStore.","solutions":["Fix the XML so ContentLocatorGroup contains only ContentLocator or ContentLocatorPart child elements.","Regenerate the annotation store instead of hand-editing it.","Catch XmlException during store load and fall back to a fresh store or skip the malformed annotation."],"exampleFix":"// before (invalid)\n<ContentLocatorGroup><Foo/></ContentLocatorGroup>\n// after (valid)\n<ContentLocatorGroup><ContentLocator><ContentLocatorPart PartType=\"...\"/></ContentLocator></ContentLocatorGroup>","handlingStrategy":"try-catch","validationCode":"XDocument doc = XDocument.Parse(xml);\nbool valid = doc.Root?.Elements().All(e => e.Name.LocalName is \"ContentLocator\" or \"ContentLocatorPart\") == true;","typeGuard":"bool IsValidLocatorGroup(XElement g) => g.Elements().All(e => e.Name.LocalName is \"ContentLocator\" or \"ContentLocatorPart\");","tryCatchPattern":"try { store.Load(stream); } catch (XmlException ex) { log.Warn(ex, \"Corrupt annotation store\"); store = CreateFreshStore(); }","preventionTips":["Never hand-edit annotation store XML","Validate store files against the annotations schema","Back up stores before programmatic modification"],"tags":["wpf","annotations","xml","schema"],"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"}