dotnet/wpf · error · XmlException

SR.Format(SR.RequiredAttributeMissing…

Error message

SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.Id, AnnotationXmlConstants.Elements.Annotation)

What it means

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.

Solutions

  1. Add the required Id attribute with a valid GUID to the <Annotation> element.
  2. Regenerate the annotation XML from the application that created it.
  3. Fix the attribute name casing/spelling to exactly 'Id'.
  4. Validate the XML against the annotations schema before loading.

Example fix

// before
<Annotation TypeName="Highlight" ...>
// after
<Annotation Id="8f5a1a2b-3c4d-5e6f-7a8b-9c0d1e2f3a4b" TypeName="Highlight" ...>
Defensive patterns

Strategy: validation

Validate before calling

bool HasRequiredId(XElement el) => el.Attribute("Id") is XAttribute id && Guid.TryParse(id.Value, out _);

Try / catch

try { annotationStore.Load(stream); } catch (XmlException ex) { log.Error("Missing/invalid annotation Id: " + ex.Message); }

Prevention

When it happens

Trigger: 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).

Common situations: XML files truncated or trimmed by other tools, manually authored annotation streams, or files where the Id attribute name was altered.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/748327e0ff4c90ab. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs:672

                        }
                        else
                        {
                            // More than one colon
                            throw new FormatException(SR.Format(SR.InvalidAttributeValue, AnnotationXmlConstants.Attributes.TypeName));
                        }
                        break;

                    default:
                        if (!Annotation.IsNamespaceDeclaration(reader))
                           throw new XmlException(SR.Format(SR.UnexpectedAttribute, reader.LocalName, AnnotationXmlConstants.Elements.Annotation));
                       break;
                }
            }

            // Test to see if any required attribute was missing
            if (_id.Equals(Guid.Empty))
            {
                throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.Id, AnnotationXmlConstants.Elements.Annotation));
            }
            if (_created.Equals(DateTime.MinValue))
            {
                throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.CreationTime, AnnotationXmlConstants.Elements.Annotation));
            }
            if (_modified.Equals(DateTime.MinValue))
            {
                throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.LastModificationTime, AnnotationXmlConstants.Elements.Annotation));
            }
            if (_typeName == null)
            {
                throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.TypeName, AnnotationXmlConstants.Elements.Annotation));
            }

            // Move back to the parent "Annotation" element
            reader.MoveToContent();
        }

View on GitHub (pinned to 81131a70a4)