{"record":{"id":"7bfc581282d86ec7","repo":"dotnet/wpf","slug":"sr-cannotchangeaftersealed-conditioncollection","errorCode":null,"errorMessage":"SR.CannotChangeAfterSealed","messagePattern":"SR\\.CannotChangeAfterSealed","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ConditionCollection.cs","lineNumber":101,"sourceCode":"        {\n            _sealed = true;\n\n            // Seal all the conditions\n            for (int i=0; i<Count; i++)\n            {\n                this[i].Seal(type);\n            }\n        }\n\n        #endregion InternalMethods\n        \n        #region PrivateMethods\n\n        private void CheckSealed()\n        {\n            if (_sealed)\n            {\n                throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"ConditionCollection\"));\n            }\n        }\n        \n        private void ConditionValidation(object value)\n        {\n            ArgumentNullException.ThrowIfNull(value);\n\n            Condition condition = value as Condition;\n            if (condition == null)\n            {\n                throw new ArgumentException(SR.MustBeCondition);\n            }\n        }\n\n        #endregion PrivateMethods\n\n        #region Data\n    ","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ConditionCollection.cs#L83-L119","documentation":"InvalidOperationException from ConditionCollection.CheckSealed: the collection has been sealed (its owning trigger/style was sealed), after which modifications (Clear/Insert/Remove/Set) are no longer permitted, so any mutating call is rejected.","triggerScenarios":"Calling Clear(), Add/Insert, Remove, or this[index] setter on a ConditionCollection after its style was sealed (i.e., after the style was applied/used).","commonSituations":"Runtime edits to a trigger's condition collection on an applied style; shared application-level resources being mutated at runtime.","solutions":["Add all conditions before the Style/Trigger is put into use (sealing happens on first use or explicit Seal)","Create a new ConditionCollection instead of modifying a sealed one"],"exampleFix":"// before\nappliedStyle.Triggers[0].Conditions.Clear(); // throws\n// after\nvar newStyle = BuildStyleWithConditions();\nbutton.Style = newStyle;","handlingStrategy":"validation","validationCode":"if (conditions is ConditionCollection cc && cc.IsReadOnly)\n    throw new InvalidOperationException(\"Collection is sealed; build a new style instead\");","typeGuard":null,"tryCatchPattern":"try { conditions.Clear(); }\ncatch (InvalidOperationException ex) { /* rebuild style/trigger and re-apply */ }","preventionTips":["Check collection read-only/sealed state before mutating.","Treat condition collections on applied styles as immutable.","Rebuild and swap the whole Style rather than editing in place."],"tags":["wpf","sealed","collection"],"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"}