{"record":{"id":"49c12a3cd9b8a54e","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedparametertype-o-gettype-typeof-setter","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedParameterType, o.GetType(), typeof(Setter))","messagePattern":"SR\\.Format\\(SR\\.UnexpectedParameterType, o\\.GetType\\(\\), typeof\\(Setter\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Trigger.cs","lineNumber":181,"sourceCode":"        ///</param>\n        void IAddChild.AddText (string text)\n        {\n            // Verify Context Access\n            VerifyAccess();\n\n            XamlSerializerUtil.ThrowIfNonWhiteSpaceInAddText(text, this);\n        }\n\n        // Shared by PropertyTrigger, MultiPropertyTrigger, DataTrigger, MultiDataTrigger\n        internal static Setter CheckChildIsSetter( object o )\n        {\n            ArgumentNullException.ThrowIfNull(o);\n\n            Setter setter = o as Setter;\n\n            if (setter == null)\n            {\n                throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, o.GetType(), typeof(Setter)), nameof(o));\n            }\n\n            return setter;\n        }\n\n        internal sealed override void Seal()\n        {\n            if (IsSealed)\n            {\n                return;\n            }\n\n            if (_property != null)\n            {\n                // Ensure valid condition\n                if (!_property.IsValidValue(_value))\n                {\n                    throw new InvalidOperationException(SR.Format(SR.InvalidPropertyValue, _value, _property.Name ));","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Trigger.cs#L163-L199","documentation":"TriggerActionCollection (Trigger) validates that items added to a TriggerActionCollection are Setter instances via CheckChildIsSetter. Passing any other object type throws ArgumentException with SR.UnexpectedParameterType naming the actual type and expected Setter type.","triggerScenarios":"Adding a non-Setter (e.g. a TriggerAction, EventSetter in the wrong collection, or arbitrary object) to an EventTrigger/Trigger action collection, or calling the internal validation path with a wrong-typed item.","commonSituations":"Programmatic style construction where the wrong collection is used (Setters vs Actions); refactoring that moved setters into action collections.","solutions":["Add only Setter instances to this collection; use Trigger.Setters for property setters.","If you meant an action, use the correct collection (e.g. EventTrigger.Actions for TriggerAction objects).","Check the object type before adding: if (item is Setter) collection.Add(item);"],"exampleFix":"// before\ntrigger.Setters.Add(new TriggerAction()); // throws\n// after\ntrigger.Setters.Add(new Setter(UIElement.OpacityProperty, 0.5));","handlingStrategy":"type-guard","validationCode":"if (item is not Setter) throw new ArgumentException($\"Expected Setter, got {item?.GetType().Name}\");","typeGuard":"static bool IsSetter(object o) => o is Setter;","tryCatchPattern":"try { collection.Add(item); }\ncatch (ArgumentException ex) { log.Error($\"Wrong collection for {item.GetType().Name}: {ex.Message}\"); }","preventionTips":["Add Setter objects only to Trigger.Setters","Use EventTrigger.Actions for TriggerAction objects","Verify collection semantics when refactoring style construction code"],"tags":["wpf","trigger","setter","argument-exception","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"}