dotnet/wpf · error · XmlException
SR.Format(SR.RequiredAttributeMissing…
Error message
SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.Id, AnnotationXmlConstants.Elements.Annotation)
What it means
FindAnnotationIds throws XmlException (SR.RequiredAttributeMissing) while parsing the store XML when an <Annotation> element lacks its required 'Id' attribute (or it is empty). The store's schema mandates a Guid Id on every annotation element.
Solutions
- Fix the store XML: give every <Annotation> element an Id="<guid>" attribute matching a valid Guid.
- Restore the store file from a known-good backup or re-create the annotation store.
- Validate the annotation stream against the annotations schema before loading it.
- If merging foreign annotation data, assign new Guids to annotations missing Ids before writing them to the stream.
Example fix
// before (store XML) <Annotation xmlns="http://schemas.microsoft.com/windows/annotations/2003/11/base"> // after <Annotation Id="a3f0c2e1-1111-4bbb-9ccc-000000000001" xmlns="http://schemas.microsoft.com/windows/annotations/2003/11/base">
Defensive patterns
Strategy: try-catch
Validate before calling
var doc = XDocument.Load(storePath);
var missing = doc.Descendants().Where(e => e.Name.LocalName == "Annotation" && (string)e.Attribute("Id") == null).ToList(); Try / catch
try { return store.GetAnnotations(); }
catch (XmlException ex) { log.Error("Store XML missing required Id attribute", ex); return new List<Annotation>(); } Prevention
- Never hand-edit annotation store XML; keep writer tools schema-conformant.
- Validate annotation files against the 2003/11 annotations schema before loading.
- Keep backups of annotation store files before tool-assisted edits.
When it happens
Trigger: Calling GetAnnotations()/GetAnnotationsByIds() which invoke FindAnnotationIds over an annotation stream whose XML contains an Annotation element without a valid non-empty Id attribute; also triggered by LoadStream on a corrupted or hand-edited store file.
Common situations: Hand-editing or post-processing the annotations XML and stripping the Id attribute; a third-party tool generating non-conforming annotation streams; truncated/corrupted store file; loading a file saved by a different/broken writer version.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- SR.Format(SR.InvalidXmlContent…
- SR.Format(SR.InvalidXmlContent…
- SR.InvalidXmlContent
- " }} " element found. Expected fixed page element ( }} ).
- Can't Assign to Known Member attributes
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/a3a241448169ac2f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/XmlStreamStore.cs:566
// Lock the object so nobody can change the document
// while the query is executed
lock (SyncRoot)
{
CheckStatus();
XPathNavigator navigator = _document.CreateNavigator();
XPathNodeIterator iterator = navigator.Select(queryExpression, _namespaceManager);
if (iterator != null && iterator.Count > 0)
{
retObj = new List<Guid>(iterator.Count);
foreach (XPathNavigator node in iterator)
{
string nodeId = node.GetAttribute("Id", "");
if (String.IsNullOrEmpty(nodeId))
{
throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.Id, AnnotationXmlConstants.Elements.Annotation));
}
try
{
annId = XmlConvert.ToGuid(nodeId);
}
catch (FormatException fe)
{
throw new InvalidOperationException(SR.CannotParseId, fe);
}
retObj.Add(annId);
}
}
else
{
retObj = new List<Guid>(0);
}View on GitHub (pinned to 81131a70a4)