{"record":{"id":"b9c9b863b3244f6c","repo":"dotnet/wpf","slug":"sr-childnamemustbenonempty","errorCode":null,"errorMessage":"SR.ChildNameMustBeNonEmpty","messagePattern":"SR\\.ChildNameMustBeNonEmpty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs","lineNumber":191,"sourceCode":"        {\n            // Not allowed to use Style to affect the StyleProperty.\n            if (dp == FrameworkElement.StyleProperty)\n            {\n                throw new ArgumentException(SR.StylePropertyInStyleNotAllowed);\n            }\n        }\n\n        /// <summary>\n        ///     Parameter validation work common to the SetXXXX methods that deal\n        /// with visual tree child nodes.\n        /// </summary>\n        internal string ProcessParametersVisualTreeChild(DependencyProperty dp, string target)\n        {\n            ArgumentNullException.ThrowIfNull(target);\n\n            if (target.Length == 0)\n            {\n                throw new ArgumentException(SR.ChildNameMustBeNonEmpty);\n            }\n\n            return String.Intern(target);\n        }\n\n        /// <summary>\n        ///     After the parameters have been validated, store it in the\n        /// PropertyValues collection.\n        /// </summary>\n        /// <remarks>\n        ///     All these will be looked at again (and processed into runtime\n        /// data structures) by Style.Seal(). We keep them around even after\n        /// that point should we need to serialize this data back out.\n        /// </remarks>\n        internal void AddToPropertyValues(string childName, DependencyProperty dp, object value, PropertyValueType valueType)\n        {\n            // Store original data\n            PropertyValue propertyValue = new PropertyValue","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs#L173-L209","documentation":"TriggerBase.ProcessParametersVisualTreeChild throws ArgumentException with SR.ChildNameMustBeNonEmpty when the TargetName given to a trigger setter/action is an empty string. TargetName must reference a named element (via x:Name / Name) within the template; an empty string is meaningless and rejected after the null check.","triggerScenarios":"Setting Setter.TargetName=\"\" or TriggerAction/TargetName to an empty string in XAML or via code (SetXxx(dp, \"\")), e.g. <Setter Property=\"Background\" TargetName=\"\" Value=\"Red\"/>.","commonSituations":"Data-bound or string-concatenated TargetName that evaluated to empty; typos leaving TargetName=\"\"; dynamic target names computed from config.","solutions":["Provide a valid TargetName matching an x:Name in the template, or omit TargetName to target the templated control","Validate the name string is non-empty before calling the API","Fix the source of the empty string (binding, config, concatenation)"],"exampleFix":"// before\nsetter.TargetName = string.Empty;\n// after\nif (!string.IsNullOrEmpty(name)) { setter.TargetName = name; }\nelse { /* omit TargetName or fix name source */ }","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(targetName))\n    throw new ArgumentException(\"TargetName must be non-empty.\");","typeGuard":"static bool IsValidTargetName(string name) => !string.IsNullOrEmpty(name);","tryCatchPattern":"try { setter.TargetName = name; }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"non-empty\") || ex.Message.Contains(\"empty\")) { /* fix name */ }","preventionTips":["Ensure referenced template elements have x:Name","Never compute TargetName from possibly-empty strings","Validate name sources (config, bindings) at startup"],"tags":["wpf","xaml","empty-string","targetname"],"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"}