{"record":{"id":"7df59f697fca04a2","repo":"dotnet/wpf","slug":"sr-cannotparseid","errorCode":null,"errorMessage":"SR.CannotParseId","messagePattern":"SR\\.CannotParseId","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs","lineNumber":575,"sourceCode":"\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                }\n            }\n\n            return retObj;\n        }\n\n        /// <summary>\n        ///     Used as AuthorChanged event handler for all annotations\n        ///     handed out by the map.\n        /// </summary>","sourceCodeStart":557,"sourceCodeEnd":593,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs#L557-L593","documentation":"FindAnnotationIds throws InvalidOperationException (SR.CannotParseId, wrapping a FormatException) when an Annotation element's Id attribute exists but is not a parseable Guid (XmlConvert.ToGuid fails).","triggerScenarios":"Loading an annotation stream whose <Annotation Id=\"...\"> values are malformed - not in the 32-digit Guid form (e.g., arbitrary strings, empty braces, wrong length); called via GetAnnotations/GetAnnotationsByIds on such a stream.","commonSituations":"Hand-written or tool-generated annotation XML with fake Ids like \"abc123\"; Ids serialized with different formats (e.g., with extra braces is OK, but truncated or hex Ids are not); data migrated from another annotation system without normalizing Ids to Guids.","solutions":["Correct the Id values in the store XML to valid Guids (Guid.TryParse each before loading).","Regenerate the annotation store, assigning Guid.NewGuid()-based Ids during migration.","Pre-validate the file: parse the XML, run Guid.TryParse on every Id attribute, fix failures before handing the stream to XmlStreamStore.","Restore from backup if the corruption is unexplained."],"exampleFix":"// before (store XML)\n<Annotation Id=\"my-annotation-1\" ...>\n\n// after\n<Annotation Id=\"d4b1c3a2-2222-4aaa-8ddd-1234567890ab\" ...>","handlingStrategy":"validation","validationCode":"foreach (var id in doc.Descendants().Where(e => e.Name.LocalName == \"Annotation\").Select(e => (string)e.Attribute(\"Id\")))\n    if (!Guid.TryParse(id, out _)) throw new FormatException($\"Invalid annotation Id: {id}\");","typeGuard":"bool IsValidAnnotationId(string id) => Guid.TryParse(id, out _);","tryCatchPattern":"try { return store.GetAnnotationsByIds(ids); }\ncatch (InvalidOperationException ex) when (ex.InnerException is FormatException) { /* quarantine bad store file */ }","preventionTips":["Migrate foreign annotation Ids through Guid.NewGuid() normalization.","Run Guid.TryParse over Id attributes before handing files to XmlStreamStore.","Generate store files only with the official AnnotationService/XmlStreamStore writer."],"tags":["xml","guid","wpf","parse-error"],"backgroundTag":"invalid-identifier-format","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"}