{"record":{"id":"781bd67d55bfd855","repo":"dotnet/wpf","slug":"sr-format-sr-namenotfound-propertyvalue-childname","errorCode":null,"errorMessage":"SR.Format(SR.NameNotFound, propertyValue.ChildName)","messagePattern":"SR\\.Format\\(SR\\.NameNotFound, propertyValue\\.ChildName\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs","lineNumber":496,"sourceCode":"        //\n        internal static void UpdateTables(\n            ref PropertyValue                                           propertyValue,\n            ref FrugalStructList<ChildRecord>                           childRecordFromChildIndex,\n            ref FrugalStructList<ItemStructMap<TriggerSourceRecord>>    triggerSourceRecordFromChildIndex,\n            ref FrugalStructList<ChildPropertyDependent>                resourceDependents,\n            ref HybridDictionary                                        dataTriggerRecordFromBinding,\n            HybridDictionary                                            childIndexFromChildName,\n            ref bool                                                    hasInstanceValues)\n        {\n            //\n            //  Record instructions for Child/Self value computation\n            //\n\n            // Query for child index (may be 0 if \"self\")\n            int childIndex = QueryChildIndexFromChildName(propertyValue.ChildName, childIndexFromChildName);\n            if (childIndex == -1)\n            {\n                throw new InvalidOperationException(SR.Format(SR.NameNotFound, propertyValue.ChildName));\n            }\n\n            object value = propertyValue.ValueInternal;\n            bool requiresInstanceStorage = RequiresInstanceStorage(ref value);\n            propertyValue.ValueInternal = value;\n\n            childRecordFromChildIndex.EnsureIndex(childIndex);\n            ChildRecord childRecord = childRecordFromChildIndex[childIndex];\n\n            int mapIndex = childRecord.ValueLookupListFromProperty.EnsureEntry(propertyValue.Property.GlobalIndex);\n\n            ChildValueLookup valueLookup = new ChildValueLookup\n            {\n                LookupType = (ValueLookupType)propertyValue.ValueType, // Maps directly to ValueLookupType for applicable values\n                Conditions = propertyValue.Conditions,\n                Property = propertyValue.Property,\n                Value = propertyValue.ValueInternal\n            };","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs#L478-L514","documentation":"Thrown by StyleHelper.UpdateTables when a template's SetterValueBindingHelper/PropertyValue (ChildValuePropertyEntry) references a child by ChildName that cannot be resolved within the template's child table. QueryChildIndexFromChildName returns -1 because the name is not registered in the template namescope/child name map, so WPF throws InvalidOperationException(NameNotFound).","triggerScenarios":"A template trigger or setter with TargetName=\"X\" where X does not match any named element (x:Name/Name) in the template's visual tree — e.g. typo'd TargetName, the named element was removed/renamed, or TargetName points outside the template. Surfaces when the template's property value tables are updated (template seal/apply).","commonSituations":"Renaming or deleting a template part without updating trigger TargetName references; misspelled TargetName in XAML; styles shared across templates where one template lacks the referenced part; refactoring XAML that split templates and left dangling TargetNames.","solutions":["Fix the TargetName to exactly match an x:Name present in the same ControlTemplate/DataTemplate.","Add or restore the named element the setter targets (give the target part x:Name=\"X\").","Remove the orphaned trigger/setter whose target no longer exists.","Search the template for all TargetName=\"...\" references and diff them against the set of x:Name attributes to find dangling ones before applying."],"exampleFix":"<!-- before -->\n<ControlTemplate TargetType=\"Button\">\n  <Border>\n    <ContentPresenter x:Name=\"Presenter\"/>\n  </Border>\n  <ControlTemplate.Triggers>\n    <Trigger Property=\"IsMouseOver\" Value=\"True\">\n      <Setter TargetName=\"HoverBorder\" Property=\"Background\" Value=\"LightBlue\"/>\n    </Trigger>\n  </ControlTemplate.Triggers>\n</ControlTemplate>\n\n<!-- after (name matches an existing part) -->\n<ControlTemplate TargetType=\"Button\">\n  <Border x:Name=\"HoverBorder\">\n    <ContentPresenter x:Name=\"Presenter\"/>\n  </Border>\n  <ControlTemplate.Triggers>\n    <Trigger Property=\"IsMouseOver\" Value=\"True\">\n      <Setter TargetName=\"HoverBorder\" Property=\"Background\" Value=\"LightBlue\"/>\n    </Trigger>\n  </ControlTemplate.Triggers>\n</ControlTemplate>","handlingStrategy":"validation","validationCode":"// Ensure every Trigger/Setters TargetName exists as an x:Name in the template\nbool targetNamesResolve(ControlTemplate t) {\n    var named = new HashSet<string>();\n    CollectNames(t.VisualTree, named);          // walk FrameworkElementFactory tree for x:Name values\n    return t.Triggers.Cast<TriggerBase>()\n        .SelectMany(tr => tr is MultiTrigger mt ? mt.Setters : tr.Setters.Cast<SetterBase>())\n        .OfType<Setter>().Where(s => s.TargetName != null)\n        .All(s => named.Contains(s.TargetName));\n}","typeGuard":"bool hasNamedPart(ControlTemplate t, string name) =>\n    t != null && t.VisualTree != null && FindNamedFactory(t.VisualTree, name) != null;","tryCatchPattern":"try { element.ApplyTemplate(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"name\") || ex.Message.Contains(\"Name\"))\n{\n    // diff TargetName references against x:Name parts, fix or remove the dangling setter\n}","preventionTips":["After renaming/removing template parts, grep all TargetName attributes in the same template","Keep triggers and the parts they target in the same template file to avoid drift","Run a build-time XAML lint comparing TargetName references to x:Name declarations","Prefer setting properties on the template root (TargetName omitted for container) when a named part is not truly needed"],"tags":["wpf","xaml","targetname","namescope","resource-not-found"],"backgroundTag":"entity-not-found","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"}