{"record":{"id":"a3a241448169ac2f","repo":"dotnet/wpf","slug":"sr-format-sr-requiredattributemissing-annotationxmlconstants-a3a241","errorCode":null,"errorMessage":"SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.Id, AnnotationXmlConstants.Elements.Annotation)","messagePattern":"SR\\.Format\\(SR\\.RequiredAttributeMissing, AnnotationXmlConstants\\.Attributes\\.Id, AnnotationXmlConstants\\.Elements\\.Annotation\\)","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs","lineNumber":566,"sourceCode":"\n            // Lock the object so nobody can change the document\n            // while the query is executed\n            lock (SyncRoot)\n            {\n                CheckStatus();\n\n                XPathNavigator navigator = _document.CreateNavigator();\n                XPathNodeIterator iterator = navigator.Select(queryExpression, _namespaceManager);\n\n                if (iterator != null && iterator.Count > 0)\n                {\n                    retObj = new List<Guid>(iterator.Count);\n                    foreach (XPathNavigator node in iterator)\n                    {\n                        string nodeId = node.GetAttribute(\"Id\", \"\");\n                        if (String.IsNullOrEmpty(nodeId))\n                        {\n                            throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.Id, AnnotationXmlConstants.Elements.Annotation));\n                        }\n\n                        try\n                        {\n                            annId = XmlConvert.ToGuid(nodeId);\n                        }\n                        catch (FormatException fe)\n                        {\n                            throw new InvalidOperationException(SR.CannotParseId, fe);\n                        }\n\n                        retObj.Add(annId);\n                    }\n                }\n                else\n                {\n                    retObj = new List<Guid>(0);\n                }","sourceCodeStart":548,"sourceCodeEnd":584,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs#L548-L584","documentation":"FindAnnotationIds throws XmlException (SR.RequiredAttributeMissing) while parsing the store XML when an <Annotation> element lacks its required 'Id' attribute (or it is empty). The store's schema mandates a Guid Id on every annotation element.","triggerScenarios":"Calling GetAnnotations()/GetAnnotationsByIds() which invoke FindAnnotationIds over an annotation stream whose XML contains an Annotation element without a valid non-empty Id attribute; also triggered by LoadStream on a corrupted or hand-edited store file.","commonSituations":"Hand-editing or post-processing the annotations XML and stripping the Id attribute; a third-party tool generating non-conforming annotation streams; truncated/corrupted store file; loading a file saved by a different/broken writer version.","solutions":["Fix the store XML: give every <Annotation> element an Id=\"<guid>\" attribute matching a valid Guid.","Restore the store file from a known-good backup or re-create the annotation store.","Validate the annotation stream against the annotations schema before loading it.","If merging foreign annotation data, assign new Guids to annotations missing Ids before writing them to the stream."],"exampleFix":"// before (store XML)\n<Annotation xmlns=\"http://schemas.microsoft.com/windows/annotations/2003/11/base\">\n\n// after\n<Annotation Id=\"a3f0c2e1-1111-4bbb-9ccc-000000000001\" xmlns=\"http://schemas.microsoft.com/windows/annotations/2003/11/base\">","handlingStrategy":"try-catch","validationCode":"var doc = XDocument.Load(storePath);\nvar missing = doc.Descendants().Where(e => e.Name.LocalName == \"Annotation\" && (string)e.Attribute(\"Id\") == null).ToList();","typeGuard":null,"tryCatchPattern":"try { return store.GetAnnotations(); }\ncatch (XmlException ex) { log.Error(\"Store XML missing required Id attribute\", ex); return new List<Annotation>(); }","preventionTips":["Never hand-edit annotation store XML; keep writer tools schema-conformant.","Validate annotation files against the 2003/11 annotations schema before loading.","Keep backups of annotation store files before tool-assisted edits."],"tags":["xml","schema","wpf","corrupt-data"],"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"}