dotnet/wpf · error · XmlException
SR.Format(SR.RequiredAttributeMissing…
Error message
SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.TypeName, AnnotationXmlConstants.Elements.Annotation)
What it means
ReadAttributes requires the TypeName attribute identifying the annotation type (e.g. Highlight, TextStickyNote). If _typeName is still null after attribute parsing, an XmlException is thrown because the type drives how the annotation is instantiated.
Solutions
- Add TypeName with a valid annotation type value (e.g. 'Highlight', 'TextStickyNote', 'InkStickyNote').
- Ensure the spelling matches AnnotationXmlConstants.Attributes.TypeName so it is recognized rather than rejected as unexpected.
- Regenerate the annotation stream via AnnotationStore/AnnotationService.
- Validate required attributes (Id, TypeName, CreationTime, LastModificationTime) before load.
Example fix
// before <Annotation Id="..." CreationTime="..." LastModificationTime="..."> // after <Annotation Id="..." TypeName="Highlight" CreationTime="..." LastModificationTime="...">
Defensive patterns
Strategy: validation
Validate before calling
bool HasTypeName(XElement el) => !string.IsNullOrEmpty(el.Attribute("TypeName")?.Value) && new[]{"Highlight","TextStickyNote","InkStickyNote"}.Contains(el.Attribute("TypeName").Value); Try / catch
try { annotationStore.Load(stream); } catch (XmlException ex) { log.Error("Missing annotation TypeName: " + ex.Message); } Prevention
- Always include a known TypeName value when producing annotation XML.
- Check for misspelled attribute names that end up rejected as unexpected before the missing-attribute error fires.
- Use AnnotationService/AnnotationStore to author annotation XML.
When it happens
Trigger: Loading annotation XML whose <Annotation> element lacks the TypeName attribute, or where TypeName was misspelled so it was rejected earlier as an unexpected attribute.
Common situations: Custom annotation producers that omit TypeName, hand-written XML, or attribute renamed by a transformation step.
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
- SR.Format(SR.RequiredAttributeMissing…
- SR.Format(SR.RequiredAttributeMissing…
- SR.Format(SR.RequiredAttributeMissing…
- SR.Format(SR.UnexpectedAttribute, reader.LocalName…
- " }} " element found. Expected fixed page element ( }} ).
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/cdcca03e5d8a318e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs:684
}
}
// 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;
IList changedItems = null;
switch (e.Action)
{View on GitHub (pinned to 81131a70a4)