{"record":{"id":"1e7b9fa8c8f08183","repo":"dotnet/wpf","slug":"sr-format-sr-targetnamenotfound-targetname","errorCode":null,"errorMessage":"SR.Format(SR.TargetNameNotFound, targetName)","messagePattern":"SR\\.Format\\(SR\\.TargetNameNotFound, targetName\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs","lineNumber":477,"sourceCode":"        // If the name is found on a FrameworkContentElement, an exception is thrown\n        // If the name is not found attached to anything, an exception is thrown\n        internal static FrameworkElement FindNamedFrameworkElement( FrameworkElement startElement, string targetName )\n        {\n            FrameworkElement targetFE = null;\n\n            if( targetName == null || targetName.Length == 0 )\n            {\n                targetFE = startElement;\n            }\n            else\n            {\n                DependencyObject targetObject = null;\n\n                targetObject = LogicalTreeHelper.FindLogicalNode( startElement, targetName );\n\n                if( targetObject == null )\n                {\n                    throw new ArgumentException( SR.Format(SR.TargetNameNotFound, targetName));\n                }\n\n                FrameworkObject fo = new FrameworkObject(targetObject);\n                if( fo.IsFE )\n                {\n                    targetFE = fo.FE;\n                }\n                else\n                {\n                    throw new InvalidOperationException(SR.Format(SR.NamedObjectMustBeFrameworkElement, targetName));\n                }\n            }\n\n            return targetFE;\n        }\n\n        /// <summary>\n        ///     Triggers associated with this object.  Both the triggering condition","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs#L459-L495","documentation":"FindNamedFrameworkElement throws ArgumentException when no element with the requested x:Name/Name can be found by walking the logical tree from the start element (LogicalTreeHelper.FindLogicalNode returns null). This happens while resolving a TemplateBinding/animatable target by name; the given TargetName simply does not exist under that starting element.","triggerScenarios":"Resolving a named target (e.g., Storyboard.TargetName, template trigger target) where targetName does not match any element in the logical tree beneath startElement.","commonSituations":"Storyboard TargetName referencing an element that is not in the same template/namescope; typo in the name; the target element was renamed or removed; applying a template-defined storyboard from outside the template where namescopes differ.","solutions":["Correct the TargetName string to exactly match the x:Name/Name of an element in the same logical tree/namescope","Ensure the storyboard and its target are in the same XAML namescope (define both in the same template/control)","Verify the target element exists at the time of resolution (not removed by conditional template logic)","Use FindName on the templated parent/template root to confirm the name resolves before applying the animation"],"exampleFix":"// before\n<Storyboard>\n  <DoubleAnimation Storyboard.TargetName=\"TxtBox\" Storyboard.TargetProperty=\"Opacity\" /> <!-- no 'TxtBox' exists -->\n</Storyboard>\n\n// after\n<Storyboard>\n  <DoubleAnimation Storyboard.TargetName=\"MyTextBox\" Storyboard.TargetProperty=\"Opacity\" /> <!-- matches x:Name=\"MyTextBox\" -->\n</Storyboard>","handlingStrategy":"validation","validationCode":"var target = startElement.FindName(targetName)\n             ?? LogicalTreeHelper.FindLogicalNode(startElement, targetName);\nif (target == null)\n    throw new ArgumentException($\"TargetName '{targetName}' not found in logical tree\");","typeGuard":"static bool TargetExists(DependencyObject root, string name) =>\n    LogicalTreeHelper.FindLogicalNode(root, name) != null;","tryCatchPattern":"try { ResolveNamedTarget(startElement, targetName); }\ncatch (ArgumentException ex) { log.Error($\"Storyboard target '{targetName}' missing\", ex); }","preventionTips":["Verify TargetName strings match x:Name exactly (watch for typos/renames)","Keep storyboards and their targets in the same XAML namescope","Check names exist at runtime with FindName before applying animations"],"tags":["wpf","resource-not-found","namescope","storyboard"],"backgroundTag":"resource-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"}