{"record":{"id":"4a54829adea26846","repo":"PrismLibrary/Prism","slug":"resources-invaliddelegatererefencetypeexception-formatted","errorCode":null,"errorMessage":"Resources.InvalidDelegateRerefenceTypeException (formatted with typeof(Action).FullName)","messagePattern":"Resources\\.InvalidDelegateRerefenceTypeException \\(formatted with typeof\\(Action\\)\\.FullName\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Prism.Events/EventSubscription.cs","lineNumber":26,"sourceCode":"    /// Provides a way to retrieve a <see cref=\"Delegate\"/> to execute an action depending\n    /// on the value of a second filter predicate that returns true if the action should execute.\n    /// </summary>\n    public class EventSubscription : IEventSubscription\n    {\n        private readonly IDelegateReference _actionReference;\n\n        ///<summary>\n        /// Creates a new instance of <see cref=\"EventSubscription\"/>.\n        ///</summary>\n        ///<param name=\"actionReference\">A reference to a delegate of type <see cref=\"System.Action\"/>.</param>\n        ///<exception cref=\"ArgumentNullException\">When <paramref name=\"actionReference\"/> or <see paramref=\"filterReference\"/> are <see langword=\"null\" />.</exception>\n        ///<exception cref=\"ArgumentException\">When the target of <paramref name=\"actionReference\"/> is not of type <see cref=\"System.Action\"/>.</exception>\n        public EventSubscription(IDelegateReference actionReference)\n        {\n            if (actionReference == null)\n                throw new ArgumentNullException(nameof(actionReference));\n            if (!(actionReference.Target is Action))\n                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidDelegateRerefenceTypeException, typeof(Action).FullName), nameof(actionReference));\n\n            _actionReference = actionReference;\n        }\n\n        /// <summary>\n        /// Gets the target <see cref=\"System.Action\"/> that is referenced by the <see cref=\"IDelegateReference\"/>.\n        /// </summary>\n        /// <value>An <see cref=\"System.Action\"/> or <see langword=\"null\" /> if the referenced target is not alive.</value>\n        public Action Action\n        {\n            get { return (Action)_actionReference.Target; }\n        }\n\n        /// <summary>\n        /// Gets or sets a <see cref=\"SubscriptionToken\"/> that identifies this <see cref=\"IEventSubscription\"/>.\n        /// </summary>\n        /// <value>A token that identifies this <see cref=\"IEventSubscription\"/>.</value>\n        public SubscriptionToken SubscriptionToken { get; set; }","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Events/EventSubscription.cs#L8-L44","documentation":"Same constructor as error 225's type check: non-generic EventSubscription throws ArgumentException formatted from Resources.InvalidDelegateRerefenceTypeException with typeof(Action).FullName when the provided IDelegateReference's Target is not assignable to System.Action. It tells you the referenced delegate has the wrong signature.","triggerScenarios":"Creating an EventSubscription whose actionReference wraps a Func<T>, Action with parameters, Predicate, or any delegate that fails the 'is Action' pattern test.","commonSituations":"Signature changes after refactoring an event handler; passing a filter delegate where the action reference is expected; wiring a generic PubSubEvent's strategy into a non-generic EventSubscription.","solutions":["Ensure the delegate referenced is exactly System.Action (parameterless)","Change the handler signature to match Action","Use EventSubscription<TPayload> with Action<TPayload> when the handler takes a payload"],"exampleFix":"// before\nvar sub = new EventSubscription(new DelegateReference((Action<object>)(o => { }), false));\n// after\nvar sub = new EventSubscription(new DelegateReference((Action)(() => { }), false));","handlingStrategy":"validation","validationCode":"if (!(actionReference?.Target is Action)) throw new InvalidOperationException(\"DelegateReference must wrap a parameterless Action\");","typeGuard":"bool IsActionRef(IDelegateReference r) => r?.Target is Action;","tryCatchPattern":"try { var sub = new EventSubscription(actionRef); }\ncatch (ArgumentException ex) { log.Error($\"Wrong delegate type for action: {ex.Message}\"); }","preventionTips":["Match delegate type to subscription kind (Action vs Action<TPayload> vs Predicate<TPayload>)","Recreate DelegateReference after handler signature refactors"],"tags":["prism","eventaggregator","type-mismatch","invalid-argument","delegate"],"backgroundTag":"type-mismatch","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}