{"record":{"id":"552e39c1422eceb6","repo":"dotnet/wpf","slug":"sr-mustbecondition","errorCode":null,"errorMessage":"SR.MustBeCondition","messagePattern":"SR\\.MustBeCondition","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ConditionCollection.cs","lineNumber":112,"sourceCode":"        \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    \n        private bool _sealed;\n\n        #endregion Data\n    }\n}\n\n\n","sourceCodeStart":94,"sourceCodeEnd":127,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ConditionCollection.cs#L94-L127","documentation":"ArgumentException from ConditionCollection.ConditionValidation (InsertItem/SetItem guard): the object being added to the collection is not a Condition, which is the only element type the strongly-typed collection accepts.","triggerScenarios":"Calling Add/Insert or the indexer setter on a ConditionCollection with an object that is not a Condition (e.g. raw Trigger, string, or null — null also fails earlier).","commonSituations":"Non-generic collection misuse in older code paths; reflection or data-binding pushing arbitrary items into the collection; type confusion between Trigger and Condition collections.","solutions":["Add only Condition instances to ConditionCollection","Wrap foreign values in an appropriate Condition before insertion"],"exampleFix":"// before\nconditions.Add(someTrigger); // ArgumentException\n// after\nconditions.Add(new Condition(UIElement.IsEnabledProperty, true));","handlingStrategy":"type-guard","validationCode":"if (item is not Condition)\n    throw new ArgumentException(\"Item must be a Condition\", nameof(item));","typeGuard":"bool IsCondition(object o) => o is Condition;","tryCatchPattern":"try { conditions.Add(item); }\ncatch (ArgumentException ex) { /* convert item to a Condition first */ }","preventionTips":["Only insert Condition instances into ConditionCollection.","Use generic-safe helpers that accept Condition parameters.","Distinguish ConditionCollection from TriggerCollection to avoid type confusion."],"tags":["wpf","collection","type-mismatch"],"backgroundTag":"type-mismatch","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"}