{"record":{"id":"4d2efd7fb6a238d8","repo":"dotnet/wpf","slug":"sr-invalidxmlcontent","errorCode":null,"errorMessage":"SR.InvalidXmlContent","messagePattern":"SR\\.InvalidXmlContent","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs","lineNumber":325,"sourceCode":"                                {\n                                    AnnotationResource cargo = (AnnotationResource)ResourceSerializer.Deserialize(reader);\n                                    _cargos.Add(cargo);\n                                }\n                            }\n                            reader.Read();    // Reads the \"Cargos\" end tag (or whole tag if it was empty)\n                        }\n                        else if (AnnotationXmlConstants.Elements.AuthorCollection == reader.LocalName)\n                        {\n                            CheckForNonNamespaceAttribute(reader, AnnotationXmlConstants.Elements.AuthorCollection);\n\n                            if (!reader.IsEmptyElement)\n                            {\n                                reader.Read();    // Reads the \"Authors\" start tag\n                                while (!(AnnotationXmlConstants.Elements.AuthorCollection == reader.LocalName && XmlNodeType.EndElement == reader.NodeType))\n                                {\n                                    if (!(AnnotationXmlConstants.Elements.StringAuthor == reader.LocalName && XmlNodeType.Element == reader.NodeType))\n                                    {\n                                        throw new XmlException(SR.Format(SR.InvalidXmlContent, AnnotationXmlConstants.Elements.Annotation));\n                                    }\n\n                                    XmlNode node = doc.ReadNode(reader);  // Reads the entire \"StringAuthor\" tag\n                                    if (!reader.IsEmptyElement)\n                                    {\n                                        _authors.Add(node.InnerText);\n                                    }\n                                }\n                            }\n                            reader.Read();    // Reads the \"Authors\" end tag (or whole tag if it was empty)\n                        }\n                        else\n                        {\n                            // The annotation must contain some invalid content which is not part of the schema.\n                            throw new XmlException(SR.Format(SR.InvalidXmlContent, AnnotationXmlConstants.Elements.Annotation));\n                        }\n                    }\n                }","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs#L307-L343","documentation":"ReadXml throws XmlException with SR.InvalidXmlContent when, inside the Authors collection, it encounters an element that is not the expected StringAuthor element. The annotation XML must strictly follow the Annotations schema; any other element inside Authors is rejected.","triggerScenarios":"Deserializing annotation XML whose <Authors> element contains a child element other than <StringAuthor> (e.g. a custom author element or an added extension element).","commonSituations":"Hand-edited annotation store XML; XML produced by a different or older schema version; third-party tools injecting author metadata into the Authors collection.","solutions":["Ensure every child element inside <Authors> is <StringAuthor> (or the collection is empty)","Regenerate the annotation XML using the WPF AnnotationService so it conforms to the schema","Strip or relocate non-schema elements before loading the XML with ReadXml"],"exampleFix":"// before\n<Authors><StringAuthor>alice</StringAuthor><CustomAuthor>bob</CustomAuthor></Authors>\n// after\n<Authors><StringAuthor>alice</StringAuthor><StringAuthor>bob</StringAuthor></Authors>","handlingStrategy":"validation","validationCode":"XDocument doc = XDocument.Load(annotationStream);\nvar bad = doc.Descendants(\"Authors\")\n    .SelectMany(a => a.Elements())\n    .Where(e => e.Name.LocalName != \"StringAuthor\")\n    .ToList();\nif (bad.Any()) throw new InvalidOperationException(\"Authors contains non-schema elements: \" + string.Join(\",\", bad.Select(b => b.Name.LocalName)));","typeGuard":null,"tryCatchPattern":"try\n{\n    annotation.ReadXml(reader);\n}\ncatch (XmlException ex)\n{\n    logger.LogError(ex, \"Annotation XML has invalid content inside Authors\");\n    throw new InvalidDataException(\"Annotation store does not match the annotations schema\", ex);\n}","preventionTips":["Validate annotation XML against the annotations schema before ReadXml","Only generate stores via AnnotationService/WriteXml","Reject unknown child elements of Authors at ingestion time"],"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"}