dotnet/wpf · error · XmlException

SR.Format(SR.RequiredAttributeMissing…

Error message

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

What it means

ReadAttributes requires the LastModificationTime attribute on every <Annotation> element. When _modified remains DateTime.MinValue after parsing, an XmlException is thrown because the annotations schema marks it mandatory.

Solutions

  1. Add the LastModificationTime attribute with a valid dateTime value.
  2. Regenerate the file from the WPF application that wrote it.
  3. Verify exact attribute name 'LastModificationTime' (no 'LastModified' variants).
  4. Run schema validation on the XML before load.

Example fix

// before
<Annotation Id="..." TypeName="Highlight" CreationTime="...">
// after
<Annotation Id="..." TypeName="Highlight" CreationTime="..." LastModificationTime="2026-09-14T10:00:00">
Defensive patterns

Strategy: validation

Validate before calling

bool HasLastModificationTime(XElement el) => DateTime.TryParse(el.Attribute("LastModificationTime")?.Value, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out _);

Try / catch

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

Prevention

When it happens

Trigger: Deserializing annotation XML where the <Annotation> element is missing the LastModificationTime attribute or it was renamed.

Common situations: Manually edited annotation stores, XML stripped of 'optional-looking' attributes, or files exported from non-WPF annotation tooling.

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/73600036cfc723a0. Report an issue: GitHub.

Appendix: source

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

                    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();
        }

        private void OnCargoChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            FireResourceEvent((AnnotationResource)sender, AnnotationAction.Modified, CargoChanged);
        }

        private void OnCargosChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            AnnotationAction action = AnnotationAction.Added;

View on GitHub (pinned to 81131a70a4)