{"record":{"id":"4949a7ac8725a2c3","repo":"dotnet/wpf","slug":"cannotchangeaftersealed-sr-format-sr","errorCode":"CannotChangeAfterSealed","errorMessage":"SR.Format(SR.CannotChangeAfterSealed, \"ControllableStoryboardAction\")","messagePattern":"SR\\.Format\\(SR\\.CannotChangeAfterSealed, \"ControllableStoryboardAction\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/ControllableStoryboardAction.cs","lineNumber":48,"sourceCode":"    {\n    }\n    \n    /// <summary>\n    ///     Name to use for resolving the storyboard reference needed.  This\n    /// points to a BeginStoryboard instance, and we're controlling that one.\n    /// </summary>\n    [DefaultValue(null)]\n    public string BeginStoryboardName\n    {\n        get\n        {\n            return _beginStoryboardName;\n        }\n        set\n        {\n            if (IsSealed)\n            {\n                throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"ControllableStoryboardAction\"));\n            }\n\n            // Null is allowed to wipe out existing name - as long as another\n            //  valid name is set before Invoke time.\n            _beginStoryboardName = value;\n        }\n    }\n\n    internal sealed override void Invoke( FrameworkElement fe, FrameworkContentElement fce, Style targetStyle, FrameworkTemplate frameworkTemplate, Int64 layer )\n    {\n        Debug.Assert( fe != null || fce != null, \"Caller of internal function failed to verify that we have a FE or FCE - we have neither.\" );\n        Debug.Assert( targetStyle != null || frameworkTemplate != null,\n            \"This function expects to be called when the associated action is inside a Style/Template.  But it was not given a reference to anything.\" );\n\n        INameScope nameScope = null;\n        if( targetStyle != null )\n        {\n            nameScope = targetStyle;","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/ControllableStoryboardAction.cs#L30-L66","documentation":"ControllableStoryboardAction.BeginStoryboardName throws InvalidOperationException (SR.CannotChangeAfterSealed for \"ControllableStoryboardAction\") when the name is changed after the action is sealed. The name links a control action (Pause/Resume/Stop) to a BeginStoryboard, and sealed actions are immutable.","triggerScenarios":"Setting BeginStoryboardName on a PauseStoryboard/ResumeStoryboard/SeekStoryboard/StopStoryboard whose IsSealed is true - i.e. after its containing trigger collection was sealed.","commonSituations":"Mutating shared style/template storyboard control actions at runtime, or reusing a cached control action instance after it has been used in a sealed template.","solutions":["Create a new ControllableStoryboardAction instance with the desired BeginStoryboardName.","Set BeginStoryboardName before adding the action to the Trigger or before the containing template seals.","Replace the sealed action in the trigger's actions collection with a fresh, configured one."],"exampleFix":"// before\nsealedPauseAction.BeginStoryboardName = \"begin\"; // throws\n// after\nvar pauseAction = new PauseStoryboard { BeginStoryboardName = \"begin\" };\ntrigger.Actions[0] = pauseAction;","handlingStrategy":"try-catch","validationCode":"if (!controlAction.IsSealed)\n    controlAction.BeginStoryboardName = \"begin\";","typeGuard":null,"tryCatchPattern":"try { controlAction.BeginStoryboardName = name; }\ncatch (InvalidOperationException ex) { /* create a new action instance instead */ }","preventionTips":["Check IsSealed before changing BeginStoryboardName on control actions","Match BeginStoryboardName exactly to the BeginStoryboard's Name (including x:Name registration)","Rebuild control actions rather than mutating shared sealed instances"],"tags":["wpf","animation","immutable-state","csharp"],"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"}