dotnet/wpf · error · ArgumentException

SR.TypeNameMustBeSpecified

Error message

SR.TypeNameMustBeSpecified

What it means

The Annotation(XmlQualifiedName) constructor requires a fully qualified annotation type: ArgumentNullException for a null type, and ArgumentException(SR.TypeNameMustBeSpecified) when the XmlQualifiedName's Name is null or empty. Annotations must identify their type to be persisted and resolved.

Solutions

  1. Pass an XmlQualifiedName with a non-empty Name, e.g. new XmlQualifiedName("note", "http://schemas.example.com/annotations")
  2. Validate annotationType.Name before constructing the Annotation
  3. Supply both Name and Namespace (Namespace is checked next at the same call site)
  4. Fix the source of the blank name — e.g. a config or XML element missing the required attribute

Example fix

// before
var ann = new Annotation(new XmlQualifiedName());
// after
var ann = new Annotation(new XmlQualifiedName("note", "http://schemas.example.com/annotations"));
Defensive patterns

Strategy: validation

Validate before calling

if (annotationType is null || string.IsNullOrEmpty(annotationType.Name) || string.IsNullOrEmpty(annotationType.Namespace))
    throw new ArgumentException("Annotation type requires Name and Namespace.");
var ann = new Annotation(annotationType);

Type guard

bool IsValidAnnotationType(XmlQualifiedName t) =>
    t is { Name: { Length: > 0 }, Namespace: { Length: > 0 } };

Try / catch

try { var ann = new Annotation(annotationType); }
catch (ArgumentException ex) when (ex.ParamName?.StartsWith("annotationType") == true)
{
    // log/repair the annotation type before retrying
}

Prevention

When it happens

Trigger: new Annotation(new XmlQualifiedName()) or new Annotation(new XmlQualifiedName("")) — an XmlQualifiedName with an empty Name; passing a default-constructed XmlQualifiedName.

Common situations: Building the annotation type dynamically and forgetting to set the Name; deserializing configuration where the type name field was blank; passing XmlQualifiedName.Empty (which has an empty Name).

Related errors


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

Appendix: source

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

            _id = Guid.Empty;
            _created = DateTime.MinValue;
            _modified = DateTime.MinValue;

            Init();
        }

        /// <summary>
        ///     Creates an instance of Annotation with the specified type name.
        /// </summary>
        /// <param name="annotationType">fully qualified type name of the new Annotation</param>
        /// <exception cref="ArgumentNullException">annotationType is null</exception>
        /// <exception cref="ArgumentException">annotationType's Name or Namespace is null or empty string</exception>
        public Annotation(XmlQualifiedName annotationType)
        {
            ArgumentNullException.ThrowIfNull(annotationType);
            if (String.IsNullOrEmpty(annotationType.Name))
            {
                throw new ArgumentException(SR.TypeNameMustBeSpecified, "annotationType.Name");// needs better message
            }
            if (String.IsNullOrEmpty(annotationType.Namespace))
            {
                throw new ArgumentException(SR.TypeNameMustBeSpecified, "annotationType.Namespace");//needs better message
            }

            _id = Guid.NewGuid();
            _typeName = annotationType;

            // For an new instance of Annotation, _created should be == with _modified
            _created = DateTime.Now;
            _modified = _created;

            Init();
        }

        /// <summary>
        ///     Creates an instance of Annotation with the values provided.  This

View on GitHub (pinned to 81131a70a4)