{"record":{"id":"e5ab35d92b1028aa","repo":"dotnet/wpf","slug":"cannotchangeaftersealed","errorCode":"CannotChangeAfterSealed","errorMessage":"SR.Format(SR.CannotChangeAfterSealed, \"BeginStoryboard\")","messagePattern":"SR\\.Format\\(SR\\.CannotChangeAfterSealed, \"BeginStoryboard\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/BeginStoryboard.cs","lineNumber":117,"sourceCode":"        {\n            ThrowIfSealed();\n\n            if(value != null && !System.Windows.Markup.NameValidationHelper.IsValidIdentifierName(value))\n            {\n                // Duplicate the error string thrown from DependencyObject.SetValueValidateParams\n                throw new ArgumentException(SR.Format(SR.InvalidPropertyValue, value, \"Name\"));\n            }\n            \n            // Null is OK - it's to remove whatever name was previously set.\n            _name = value;\n        }\n    }\n\n    private void ThrowIfSealed()\n    {\n        if (IsSealed)\n        {\n            throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"BeginStoryboard\"));\n        }\n    }\n    \n    // Bug #1329664 workaround to make beta 2\n    // Remove thread affinity when sealed, but before doing that, snapshot the\n    //  current Storyboard value and remove *its* thread affinity too.\n    internal override void Seal()\n    {\n        if( !IsSealed )\n        {\n            // Gets our Storyboard value.  This value may have come from a\n            //  ResourceReferenceExpression or might have been a deferred\n            //  reference that has since been realized.\n            Storyboard snapshot = GetValue(StoryboardProperty) as Storyboard;\n\n            if( snapshot == null )\n            {\n                // This is the same error thrown by Begin if the Storyboard","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/BeginStoryboard.cs#L99-L135","documentation":"BeginStoryboard.ThrowIfSealed throws InvalidOperationException (SR.CannotChangeAfterSealed for \"BeginStoryboard\") when any mutable property is changed after the object has been sealed. Sealing happens when the Triggers collection containing it is sealed, after which the action is immutable.","triggerScenarios":"Setting Storyboard, HandoffBehavior, or Name on a BeginStoryboard whose IsSealed is true - e.g. mutating a template/event-trigger's BeginStoryboard after the containing style, template, or trigger collection was sealed.","commonSituations":"Modifying shared resources (styles/templates) at runtime that already contain BeginStoryboard actions, or reusing a cached BeginStoryboard instance across animations after it was sealed.","solutions":["Create a new BeginStoryboard instance instead of mutating the sealed one.","Make modifications before adding the BeginStoryboard to a Trigger's EnterActions/ExitActions or before the containing template is sealed.","Clone the configuration into an unsealed object and replace it in the trigger."],"exampleFix":"// before\nsealedBeginStoryboard.HandoffBehavior = HandoffBehavior.Compose; // throws\n// after\nvar newAction = new BeginStoryboard { Storyboard = storyboard, HandoffBehavior = HandoffBehavior.Compose };\ntrigger.EnterActions[0] = newAction;","handlingStrategy":"try-catch","validationCode":"if (!beginStoryboard.IsSealed)\n    beginStoryboard.HandoffBehavior = HandoffBehavior.Compose;","typeGuard":null,"tryCatchPattern":"try { beginStoryboard.Name = newName; }\ncatch (InvalidOperationException ex) { /* construct a replacement instead of mutating */ }","preventionTips":["Check IsSealed before mutating any BeginStoryboard property","Configure triggers fully before adding to styles/templates that get sealed","Treat sealed trigger actions as immutable; build new instances for changes"],"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-22T01:17:13.364Z"}