dotnet/wpf · error · XmlException

SR.Format(SR.RequiredAttributeMissing…

Error message

SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.ItemValue, AnnotationXmlConstants.Elements.Item)

What it means

Each <Item> element must also carry a Value attribute; when it is absent, ReadXml throws XmlException(SR.RequiredAttributeMissing, "Value", "Item"). Both attributes are mandatory because the Item encodes one name/value pair of the locator part.

Solutions

  1. Add the Value attribute to every Item element; use Value="" for empty values.
  2. Fix the writer so it always emits both Name and Value, even when the value is empty.
  3. Pre-validate the annotation XML before passing it to the store.

Example fix

// before
<Item Name="key"/>
// after
<Item Name="key" Value=""/>
Defensive patterns

Strategy: validation

Validate before calling

foreach (var item in doc.Descendants("Item"))
    if ((string?)item.Attribute("Value") is null)
        throw new InvalidDataException("Item is missing required Value attribute");

Try / catch

try { LoadAnnotations(stream); }
catch (XmlException ex) when (ex.Message.Contains("Value")) { /* repair the Item elements or skip the file */ }

Prevention

When it happens

Trigger: Deserializing an annotations stream where an Item element has only a Name attribute, e.g. <Item Name="k"/> (perhaps intended as an empty value but written without Value).

Common situations: Custom annotation writers skipping empty-string values instead of serializing Value=""; hand-edited files; template XML missing attributes.

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


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPartList.cs:251

                                            name = reader.Value;
                                            break;
                                        case AnnotationXmlConstants.Attributes.ItemValue:
                                            value = reader.Value;
                                            break;
                                        default:
                                            if (!Annotation.IsNamespaceDeclaration(reader))
                                                throw new XmlException(SR.Format(SR.UnexpectedAttribute, reader.LocalName, AnnotationXmlConstants.Elements.Item));
                                            break;
                                    }
                                }

                                if (name == null)
                                {
                                    throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.ItemName, AnnotationXmlConstants.Elements.Item));
                                }
                                if (value == null)
                                {
                                    throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.ItemValue, AnnotationXmlConstants.Elements.Item));
                                }

                                reader.MoveToContent();

                                part.NameValuePairs.Add(name, value);

                                bool isEmpty = reader.IsEmptyElement;

                                reader.Read();  // Read the beginning of the complete Item tag

                                if (!isEmpty)
                                {
                                    if (!(XmlNodeType.EndElement == reader.NodeType && AnnotationXmlConstants.Elements.Item == reader.LocalName))
                                    {
                                        // Should not contain any content, only attributes
                                        throw new XmlException(SR.Format(SR.InvalidXmlContent, AnnotationXmlConstants.Elements.Item));
                                    }
                                    else

View on GitHub (pinned to 81131a70a4)