{"record":{"id":"50f7958eb402748c","repo":"dotnet/wpf","slug":"sr-namenotemptystring","errorCode":null,"errorMessage":"SR.NameNotEmptyString","messagePattern":"SR\\.NameNotEmptyString","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs","lineNumber":144,"sourceCode":"                _text = value;\n            }\n        }\n\n        /// <summary>\n        ///     Style identifier\n        /// </summary>\n        public string Name\n        {\n            get { return _childName; }\n            set\n            {\n                if (_sealed)\n                {\n                    throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"FrameworkElementFactory\"));\n                }\n                if (value == string.Empty)\n                {\n                    throw new ArgumentException(SR.NameNotEmptyString);\n                }\n\n                _childName = value;\n            }\n        }\n\n\n        /// <summary>\n        ///     Add a factory child to this factory\n        /// </summary>\n        /// <param name=\"child\">Child to add</param>\n        public void AppendChild(FrameworkElementFactory child)\n        {\n            if (_sealed)\n            {\n                throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"FrameworkElementFactory\"));\n            }\n","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs#L126-L162","documentation":"The FrameworkElementFactory.Name setter throws this ArgumentException when assigned string.Empty. An empty string is not a valid element name; the factory requires either null (no name) or a non-empty name string. This keeps template part naming (TemplatePart/name registration) well-formed.","triggerScenarios":"factory.Name = string.Empty; or a computed name variable that evaluates to \"\" (e.g. string.Concat of missing parts, or Name = someString where someString == \"\").","commonSituations":"Names sourced from configuration or data-driven template generation where the value is present but empty; sanitization code that strips the name to nothing before assignment.","solutions":["Pass a non-empty name, or pass null when the factory should be unnamed.","Validate/trim the name string before assignment and fall back to null if empty.","Fix the upstream generator that produces empty names."],"exampleFix":"// before\nfef.Name = userSuppliedName; // throws when \"\"\n\n// after\nvar name = string.IsNullOrWhiteSpace(userSuppliedName) ? null : userSuppliedName.Trim();\nfef.Name = name; // null means unnamed, non-empty is accepted","handlingStrategy":"validation","validationCode":"if (name is \"\") throw new ArgumentException(\"Name must be null or non-empty, not empty string.\");\nfactory.Name = name;","typeGuard":"string? NormalizeName(string? s) => string.IsNullOrEmpty(s) ? null : s;","tryCatchPattern":"try { factory.Name = name; }\ncatch (ArgumentException ex) { logger.LogError(ex, \"Empty name supplied for factory\"); }","preventionTips":["Normalize empty strings to null before assigning names.","Validate user/config-supplied names at the boundary.","Trim inputs and reject whitespace-only names the same as empty."],"tags":["wpf","xaml","frameworkelementfactory","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"}