{"record":{"id":"6461d5be56787b5a","repo":"dotnet/wpf","slug":"sr-storyboard-neverapplied","errorCode":null,"errorMessage":"SR.Storyboard_NeverApplied","messagePattern":"SR\\.Storyboard_NeverApplied","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs","lineNumber":1947,"sourceCode":"    {\n        Clock clock = null;\n        WeakReference clockReference = null;\n\n        HybridDictionary clocks = StoryboardClockTreesField.GetValue(o);\n\n        if (clocks != null)\n        {\n            clockReference = clocks[this] as WeakReference;\n        }\n\n        if (clockReference == null)\n        {\n            if (throwIfNull)\n            {\n                // This exception indicates that the storyboard has never been applied.\n                // We check the weak reference because the only way it can be null\n                // is if it had never been put in the dictionary.\n                throw new InvalidOperationException(SR.Storyboard_NeverApplied);\n            }\n            else  if (TraceAnimation.IsEnabledOverride )\n            {\n                TraceAnimation.Trace(\n                    TraceEventType.Warning,\n                    TraceAnimation.StoryboardNotApplied,\n                    operation,\n                    this,\n                    o);\n            }\n        }\n\n\n\n        if (clockReference != null)\n        {\n            clock = clockReference.Target as Clock;\n","sourceCodeStart":1929,"sourceCodeEnd":1965,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs#L1929-L1965","documentation":"Thrown when a control API (e.g. Pause/Resume/Remove/Seek-style operations that need the storyboard's applied state) finds the storyboard's weak reference missing from the containing object's internal dictionary, meaning the storyboard was never applied to that object. Control operations require a previously applied (Begin'ed) storyboard; one that was only instantiated has no clock to control.","triggerScenarios":"Calling storyboard.Pause/Resume/Seek/Remove/SkipToFill (or the IControllableStorybard-related helpers) on a Storyboard that was never Begin'ed against the target, or Begin'ed against a different containing object.","commonSituations":"Pausing an animation whose Begin call was skipped due to an earlier exception; using a new Storyboard instance each frame and keeping only the newest reference; applying to one Window but controlling against another.","solutions":["Call storyboard.Begin(containingObject, isControllable: true) before any control operation and keep the same Storyboard instance.","Track applied storyboards (e.g. in a field) and pass the same instance and containing object to Pause/Resume/Seek.","Guard control calls: only invoke them if you know Begin succeeded (set a flag after Begin).","If using BeginStoryboard in XAML, name it and control through its ControllableStoryboardAction rather than constructing a separate Storyboard."],"exampleFix":"// before\nvar sb = new Storyboard(...);\nsb.Pause(this); // never applied\n// after\nvar sb = new Storyboard(...);\nsb.Begin(this, isControllable: true);\n// ... later\nsb.Pause(this);","handlingStrategy":"try-catch","validationCode":"bool applied = storyboardField != null && storyboardApplied; // set storyboardApplied = true right after Begin(this, isControllable: true)","typeGuard":"bool IsApplied(Storyboard sb, FrameworkElement host) => sb != null && storyboardApplied && ReferenceEquals(host, storyboardHost);","tryCatchPattern":"try { sb.Pause(this); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"never been applied\")) { sb.Begin(this, isControllable: true); }","preventionTips":["Always Begin with isControllable: true if you will Pause/Resume/Seek","Keep one Storyboard instance per animated host, stored in a field","Apply and control with the exact same containing object","Check for a successful Begin before issuing control operations"],"tags":["wpf","animation","storyboard","invalid-state","lifecycle"],"backgroundTag":"invalid-state-transition","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"}