{"record":{"id":"53385f5cd0316339","repo":"dotnet/wpf","slug":"sr-typenamemustbespecified-locatorpart","errorCode":null,"errorMessage":"SR.TypeNameMustBeSpecified","messagePattern":"SR\\.TypeNameMustBeSpecified","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPart.cs","lineNumber":48,"sourceCode":"        //\n        //  Constructors\n        //\n        //------------------------------------------------------\n\n        #region Constructors\n\n        /// <summary>\n        ///     Creates a ContentLocatorPart with the specified type name and namespace.\n        /// </summary>\n        /// <param name=\"partType\">fully qualified locator part's type</param>\n        /// <exception cref=\"ArgumentNullException\">partType is null</exception>\n        /// <exception cref=\"ArgumentException\">partType.Namespace or partType.Name is null or empty string</exception>\n        public ContentLocatorPart(XmlQualifiedName partType)\n        {\n            ArgumentNullException.ThrowIfNull(partType);\n            if (String.IsNullOrEmpty(partType.Name))\n            {\n                throw new ArgumentException(SR.TypeNameMustBeSpecified, \"partType.Name\");\n            }\n            if (String.IsNullOrEmpty(partType.Namespace))\n            {\n                throw new ArgumentException(SR.TypeNameMustBeSpecified, \"partType.Namespace\");\n            }\n\n            _type = partType;\n            _nameValues = new ObservableDictionary();\n            _nameValues.PropertyChanged += OnPropertyChanged;\n        }\n\n        #endregion Constructors\n\n        //------------------------------------------------------\n        //\n        //  Public Methods\n        //\n        //------------------------------------------------------","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/LocatorPart.cs#L30-L66","documentation":"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\".","triggerScenarios":"new ContentLocatorPart(new XmlQualifiedName(\"\")) or new ContentLocatorPart(new XmlQualifiedName(null, \"ns\")) - the qualified name's Name property is null or empty.","commonSituations":"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.","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."],"exampleFix":"// before\nvar qname = new XmlQualifiedName();\nvar part = new ContentLocatorPart(qname); // throws\n// after\nif (string.IsNullOrEmpty(qname.Name)) throw new InvalidOperationException(\"Locator part type name is required\");\nvar part = new ContentLocatorPart(new XmlQualifiedName(\"MyPartType\", qname.Namespace));","handlingStrategy":"validation","validationCode":"if (partType == null || string.IsNullOrEmpty(partType.Name))\n    throw new ArgumentException(\"A non-empty type name is required.\", nameof(partType));","typeGuard":"static bool IsValidLocatorPartType(XmlQualifiedName q) => q != null && !string.IsNullOrEmpty(q.Name);","tryCatchPattern":"try { var part = new ContentLocatorPart(partType); }\ncatch (ArgumentException ex) when (ex.ParamName == \"partType.Name\") { /* fall back to a default part type or report */ }","preventionTips":["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."],"tags":["wpf","annotations","argument-validation"],"backgroundTag":"empty-required-field","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}