{"record":{"id":"4e852b3bf27401c9","repo":"dotnet/wpf","slug":"sr-format-sr-childnamenamepatternreserved-childname","errorCode":null,"errorMessage":"SR.Format(SR.ChildNameNamePatternReserved, _childName)","messagePattern":"SR\\.Format\\(SR\\.ChildNameNamePatternReserved, _childName\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs","lineNumber":564,"sourceCode":"\n            if (_firstChild != null)\n            {\n                // This factory has children, it must implement IAddChild so that these\n                // children can be added to the logical tree\n                if (!typeof(IAddChild).IsAssignableFrom(_type))\n                {\n                    throw new InvalidOperationException(SR.Format(SR.TypeMustImplementIAddChild, _type.Name));\n                }\n            }\n\n            ApplyAutoAliasRules();\n\n            if ((_childName != null) && (_childName != String.Empty))\n            {\n                // ChildName provided\n                if (!IsChildNameValid(_childName))\n                {\n                    throw new InvalidOperationException(SR.Format(SR.ChildNameNamePatternReserved, _childName));\n                }\n\n                _childName = String.Intern(_childName);\n            }\n            else\n            {\n                // ChildName not provided\n\n                _childName = GenerateChildName();\n            }\n\n\n            lock (_synchronized)\n            {\n                // Set delayed ChildID for all property triggers\n                for (int i = 0; i < PropertyValues.Count; i++)\n                {\n                    PropertyValue propertyValue = PropertyValues[i];","sourceCodeStart":546,"sourceCodeEnd":582,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs#L546-L582","documentation":"FrameworkElementFactory.Seal() validates the factory's ChildName against a reserved naming pattern (names starting with a reserved prefix used internally by the template system). If the child name is present but fails IsChildNameValid (it matches a reserved pattern, e.g. begins with a character/sequence the framework reserves for its own name scope bookkeeping), Seal throws InvalidOperationException. Seal is invoked when the factory is used by a template, so the error surfaces at template compile/seal time, not at factory construction.","triggerScenarios":"Setting FrameworkElementFactory.Name (which sets _childName) to a string that fails IsChildNameValid — i.e. a name matching the reserved pattern — and then using the factory in a DataTemplate/ControlTemplate so Seal() runs.","commonSituations":"Programmatically building templates in code and assigning a child name that collides with WPF's reserved name syntax instead of an ordinary XAML name; copy-pasting generated names from other systems (e.g. '$Name', ':0') into factory names.","solutions":["Choose a different child name that passes IsChildNameValid (avoid the reserved prefix pattern; use ordinary alphanumeric names).","If the name is only for element lookup, use FindName-compatible names and set Name via the factory constructor FrameworkElementFactory(Type, String) with a valid string.","If the name came from user input or an external config, sanitize/validate it before assigning to factory.Name."],"exampleFix":"// before\nvar factory = new FrameworkElementFactory(typeof(Button));\nfactory.Name = \"$reservedName\"; // reserved pattern\n// after\nvar factory = new FrameworkElementFactory(typeof(Button));\nfactory.Name = \"myButton\"; // valid, non-reserved name","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrEmpty(factory.Name) && (factory.Name.StartsWith(\"$\") || factory.Name.Contains(\":\")))\n    throw new ArgumentException($\"Child name '{factory.Name}' uses a reserved pattern\");","typeGuard":"bool IsValidChildName(string n) => string.IsNullOrEmpty(n) || !(n.StartsWith(\"$\") || n.Contains(':'));","tryCatchPattern":"try { template.Seal(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"reserved\")) { /* pick a different child name */ }","preventionTips":["Use plain alphanumeric names for factory children","Never feed external/user-supplied identifiers straight into factory.Name","Sanitize names before constructing the factory tree"],"tags":["wpf","template","invalid-identifier-format","invalid-state-transition"],"backgroundTag":"invalid-identifier-format","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"}