{"record":{"id":"9e8e4bd25ad33a5f","repo":"dotnet/wpf","slug":"sr-format-sr-invalidxmlcontent-annotationxmlconstants","errorCode":null,"errorMessage":"SR.Format(SR.InvalidXmlContent, AnnotationXmlConstants.Elements.Resource)","messagePattern":"SR\\.Format\\(SR\\.InvalidXmlContent, AnnotationXmlConstants\\.Elements\\.Resource\\)","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationResource.cs","lineNumber":190,"sourceCode":"                    {\n                        ContentLocatorBase locator = (ContentLocatorBase)LocatorGroupSerializer.Deserialize(reader);\n                        InternalLocators.Add(locator);\n                    }\n                    else if (AnnotationXmlConstants.Elements.ContentLocator == reader.LocalName)\n                    {\n                        ContentLocatorBase locator = (ContentLocatorBase)ListSerializer.Deserialize(reader);\n                        InternalLocators.Add(locator);\n                    }\n                    else if (XmlNodeType.Element == reader.NodeType)\n                    {\n                        XmlElement element = doc.ReadNode(reader) as XmlElement;\n                        InternalContents.Add(element);\n                    }\n                    else\n                    {\n                        // The resource must contain a non-XmlElement child such as plain\n                        // text which is not part of the schema.\n                        throw new XmlException(SR.Format(SR.InvalidXmlContent, AnnotationXmlConstants.Elements.Resource));\n                    }\n                }\n            }\n\n            reader.Read();   // Reads the end of the \"Resource\" 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":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationResource.cs#L172-L208","documentation":"AnnotationResource.ReadXml throws XmlException when the <Resource> element contains XML content that violates the annotation schema — specifically, a non-XmlElement child (such as plain text) directly inside the Resource element. Resource elements may only contain XmlElement children (e.g. <Cargos>, <Contents> child elements). Free-form text nodes inside Resource are schema violations.","triggerScenarios":"Deserializing an annotations XML stream (XmlStreamStore) whose <Resource> element contains raw text or CDATA as a direct child, e.g. <Resource Name=\"x\">some text</Resource> or mixed text content between child elements.","commonSituations":"Hand-edited annotation XML files; annotation files produced by an older or custom store version with a different schema; corrupted or merged annotation streams; third-party tools writing annotation XML incorrectly.","solutions":["Fix the annotation XML so <Resource> contains only XmlElement children (no bare text nodes).","Remove stray text/CDATA content directly inside <Resource> elements.","Regenerate the annotation store from the application rather than editing the XML by hand.","Validate annotation files against the annotations schema before loading them."],"exampleFix":"// before\n<Resource Name=\"note\">plain text here</Resource>\n// after\n<Resource Name=\"note\"><Cargos><Cargo>plain text here</Cargo></Cargos></Resource>","handlingStrategy":"try-catch","validationCode":"// Before loading, sanity-check the XML:\nforeach (var resource in doc.Descendants(ns + \"Resource\"))\n    if (resource.Nodes().Any(n => n is XText t && !string.IsNullOrWhiteSpace(t.Value)))\n        throw new InvalidDataException(\"Resource contains non-element text\");","typeGuard":"bool IsSchemaValidResource(XElement r) => !r.Nodes().Any(n => n is XText);","tryCatchPattern":"try { using var store = new XmlStreamStore(stream); store.LoadAnnotations(...); }\ncatch (XmlException ex) { log(ex); /* repair or regenerate annotation file */ }","preventionTips":["Never hand-edit annotation XML files; regenerate them via the app.","Keep only XmlElement children inside <Resource>.","Validate annotation files against the annotations schema before loading."],"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-21T21:30:21.729Z"}