dotnet/wpf · error · ArgumentException
SR.TypeNameMustBeSpecified
Error message
SR.TypeNameMustBeSpecified
What it means
ContentLocatorPart's constructor requires an XmlQualifiedName whose Name is non-empty. WPF Annotations throws ArgumentException(SR.TypeNameMustBeSpecified) when partType.Name is null or the empty string, because a locator part is meaningless without a type name. The parameter name reported in the exception is "partType.Name".
Solutions
- Ensure the XmlQualifiedName passed to the constructor has a non-empty Name property.
- Validate the name before constructing the ContentLocatorPart and surface a domain-specific error.
- If the name can legitimately be absent, do not create a ContentLocatorPart; model that case explicitly.
Example fix
// before
var qname = new XmlQualifiedName();
var part = new ContentLocatorPart(qname); // throws
// after
if (string.IsNullOrEmpty(qname.Name)) throw new InvalidOperationException("Locator part type name is required");
var part = new ContentLocatorPart(new XmlQualifiedName("MyPartType", qname.Namespace)); Defensive patterns
Strategy: validation
Validate before calling
if (partType == null || string.IsNullOrEmpty(partType.Name))
throw new ArgumentException("A non-empty type name is required.", nameof(partType)); Type guard
static bool IsValidLocatorPartType(XmlQualifiedName q) => q != null && !string.IsNullOrEmpty(q.Name);
Try / catch
try { var part = new ContentLocatorPart(partType); }
catch (ArgumentException ex) when (ex.ParamName == "partType.Name") { /* fall back to a default part type or report */ } Prevention
- Never use the parameterless XmlQualifiedName constructor for locator part types.
- Validate qualified names at deserialization boundaries before constructing API objects.
- Keep the namespace and name together in a single factory method that guarantees validity.
When it happens
Trigger: new ContentLocatorPart(new XmlQualifiedName("")) or new ContentLocatorPart(new XmlQualifiedName(null, "ns")) - the qualified name's Name property is null or empty.
Common situations: Building locator parts dynamically from deserialized or user-supplied XML where the local name was lost; constructing XmlQualifiedName via its parameterless default constructor and forgetting to set Name; mapping from external schemas where the element name is optional.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- InvalidEnumArgumentException("action", (int)action…
- InvalidEnumArgumentException("action", (int)action…
- SR.AnnotationAlreadyExists
- SR.IncorrectLocatorPartType
- ' ' is not a valid value for ' '.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/53385f5cd0316339.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPart.cs:48
//
// Constructors
//
//------------------------------------------------------
#region Constructors
/// <summary>
/// Creates a ContentLocatorPart with the specified type name and namespace.
/// </summary>
/// <param name="partType">fully qualified locator part's type</param>
/// <exception cref="ArgumentNullException">partType is null</exception>
/// <exception cref="ArgumentException">partType.Namespace or partType.Name is null or empty string</exception>
public ContentLocatorPart(XmlQualifiedName partType)
{
ArgumentNullException.ThrowIfNull(partType);
if (String.IsNullOrEmpty(partType.Name))
{
throw new ArgumentException(SR.TypeNameMustBeSpecified, "partType.Name");
}
if (String.IsNullOrEmpty(partType.Namespace))
{
throw new ArgumentException(SR.TypeNameMustBeSpecified, "partType.Namespace");
}
_type = partType;
_nameValues = new ObservableDictionary();
_nameValues.PropertyChanged += OnPropertyChanged;
}
#endregion Constructors
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------View on GitHub (pinned to 81131a70a4)