{"record":{"id":"748327e0ff4c90ab","repo":"dotnet/wpf","slug":"sr-format-sr-requiredattributemissing-annotationxmlconstants","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/Annotation.cs","lineNumber":672,"sourceCode":"                        }\n                        else\n                        {\n                            // More than one colon\n                            throw new FormatException(SR.Format(SR.InvalidAttributeValue, AnnotationXmlConstants.Attributes.TypeName));\n                        }\n                        break;\n\n                    default:\n                        if (!Annotation.IsNamespaceDeclaration(reader))\n                           throw new XmlException(SR.Format(SR.UnexpectedAttribute, reader.LocalName, AnnotationXmlConstants.Elements.Annotation));\n                       break;\n                }\n            }\n\n            // Test to see if any required attribute was missing\n            if (_id.Equals(Guid.Empty))\n            {\n                throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.Id, AnnotationXmlConstants.Elements.Annotation));\n            }\n            if (_created.Equals(DateTime.MinValue))\n            {\n                throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.CreationTime, AnnotationXmlConstants.Elements.Annotation));\n            }\n            if (_modified.Equals(DateTime.MinValue))\n            {\n                throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.LastModificationTime, AnnotationXmlConstants.Elements.Annotation));\n            }\n            if (_typeName == null)\n            {\n                throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.TypeName, AnnotationXmlConstants.Elements.Annotation));\n            }\n\n            // Move back to the parent \"Annotation\" element\n            reader.MoveToContent();\n        }\n","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs#L654-L690","documentation":"After reading all attributes of the <Annotation> element, ReadAttributes validates required attributes. If no valid Id attribute was found (leaving _id as Guid.Empty), it throws XmlException because every annotation must have a unique Id.","triggerScenarios":"Calling Annotation.ReadXml (directly or via XmlSerializer/AnnotationStore load) on XML whose <Annotation> element is missing the Id attribute, or whose Id is invalid/unparseable to a Guid (invalid GUID previously flagged separately, but a missing attribute yields this error).","commonSituations":"XML files truncated or trimmed by other tools, manually authored annotation streams, or files where the Id attribute name was altered.","solutions":["Add the required Id attribute with a valid GUID to the <Annotation> element.","Regenerate the annotation XML from the application that created it.","Fix the attribute name casing/spelling to exactly 'Id'.","Validate the XML against the annotations schema before loading."],"exampleFix":"// before\n<Annotation TypeName=\"Highlight\" ...>\n// after\n<Annotation Id=\"8f5a1a2b-3c4d-5e6f-7a8b-9c0d1e2f3a4b\" TypeName=\"Highlight\" ...>","handlingStrategy":"validation","validationCode":"bool HasRequiredId(XElement el) => el.Attribute(\"Id\") is XAttribute id && Guid.TryParse(id.Value, out _);","typeGuard":null,"tryCatchPattern":"try { annotationStore.Load(stream); } catch (XmlException ex) { log.Error(\"Missing/invalid annotation Id: \" + ex.Message); }","preventionTips":["Ensure every <Annotation> element carries a Guid Id when generating XML.","Round-trip annotations through AnnotationStore instead of manual XML authoring.","Schema-validate before load.","Keep attribute names exactly as the schema defines them."],"tags":["xml","wpf","deserialization"],"backgroundTag":"missing-required-argument","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"}