{"record":{"id":"710ec7ef397ae730","repo":"dotnet/wpf","slug":"sr-format-sr-requiredattributemissing-annotationxmlconstants-710ec7","errorCode":null,"errorMessage":"SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.Id, AnnotationXmlConstants.Elements.Resource)","messagePattern":"SR\\.Format\\(SR\\.RequiredAttributeMissing, AnnotationXmlConstants\\.Attributes\\.Id, AnnotationXmlConstants\\.Elements\\.Resource\\)","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationResource.cs","lineNumber":462,"sourceCode":"                {\n                    case AnnotationXmlConstants.Attributes.Id:\n                        tempId = XmlConvert.ToGuid(value);\n                        break;\n\n                    case AnnotationXmlConstants.Attributes.ResourceName:\n                        _name = value;\n                        break;\n\n                    default:\n                        if (!Annotation.IsNamespaceDeclaration(reader))\n                            throw new XmlException(SR.Format(SR.UnexpectedAttribute, reader.LocalName, AnnotationXmlConstants.Elements.Resource));\n                        break;\n                }\n            }\n\n            if (Guid.Empty.Equals(tempId))\n            {\n                throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.Id, AnnotationXmlConstants.Elements.Resource));\n            }\n\n            _id = tempId;\n\n            // Name attribute is optional, so no need to check it\n\n            // Move back to the parent \"Resource\" element\n            reader.MoveToContent();\n        }\n\n        /// <summary>\n        /// Listens for change events from the list of locators.  Fires a change event\n        /// for this resource when an event is received.\n        /// </summary>\n        private void OnLocatorsChanged(object sender, NotifyCollectionChangedEventArgs e)\n        {\n            FireResourceChanged(\"Locators\");\n        }","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationResource.cs#L444-L480","documentation":"AnnotationResource.ReadAttributes throws XmlException when a <Resource> element in the annotation XML lacks the required Id attribute. Every resource in the annotations schema must carry a Guid Id; without it the resource cannot be identified or attached to an annotation. The check fires when parsing leaves tempId at Guid.Empty.","triggerScenarios":"Deserializing annotation XML from XmlStreamStore where a <Resource> element has no Id attribute (or an Id that failed to parse to a Guid, yielding Guid.Empty).","commonSituations":"Truncated or hand-edited annotation files; annotation streams written by tools that omit Id; corrupted XML after partial writes; copy-paste edits that dropped the attribute.","solutions":["Add a unique Guid Id attribute to each <Resource> element in the annotation file.","Ensure Id attribute values are well-formed Guids (parseable by Guid.Parse).","Restore the annotation file from a backup or regenerate the store.","Validate annotation XML against the schema before loading."],"exampleFix":"// before\n<Resource Name=\"note\">\n// after\n<Resource Id=\"3f2504e0-4f89-11d3-9a0c-0305e82c3301\" Name=\"note\">","handlingStrategy":"try-catch","validationCode":"foreach (var resourceEl in doc.Descendants(ns + \"Resource\"))\n    if ((string)resourceEl.Attribute(\"Id\") == null)\n        resourceEl.SetAttributeValue(\"Id\", Guid.NewGuid());","typeGuard":"bool HasRequiredId(XElement r) => Guid.TryParse((string?)r.Attribute(\"Id\"), out _);","tryCatchPattern":"try { store = new XmlStreamStore(stream); annotations = store.LoadAnnotations(...); }\ncatch (XmlException ex) { log(ex); restoreFromBackup(); }","preventionTips":["Validate annotation XML for the required Id attribute before load.","Keep backups of annotation stores; Id attributes can be lost by truncation.","If a tool writes the XML, ensure it always emits Id."],"tags":["wpf","annotations","xml","missing-attribute"],"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-21T21:30:21.729Z"}