{"record":{"id":"365b7af71bcbe1db","repo":"PrismLibrary/Prism","slug":"resources-invaliddelegatererefencetypeexception-formatted-365b7a","errorCode":null,"errorMessage":"Resources.InvalidDelegateRerefenceTypeException (formatted with typeof(Action<TPayload>).FullName)","messagePattern":"Resources\\.InvalidDelegateRerefenceTypeException \\(formatted with typeof\\(Action<TPayload>\\)\\.FullName\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Prism.Events/EventSubscription.cs","lineNumber":108,"sourceCode":"    public class EventSubscription<TPayload> : IEventSubscription\n    {\n        private readonly IDelegateReference _actionReference;\n        private readonly IDelegateReference _filterReference;\n\n        ///<summary>\n        /// Creates a new instance of <see cref=\"EventSubscription{TPayload}\"/>.\n        ///</summary>\n        ///<param name=\"actionReference\">A reference to a delegate of type <see cref=\"System.Action{TPayload}\"/>.</param>\n        ///<param name=\"filterReference\">A reference to a delegate of type <see cref=\"Predicate{TPayload}\"/>.</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{TPayload}\"/>,\n        ///or the target of <paramref name=\"filterReference\"/> is not of type <see cref=\"Predicate{TPayload}\"/>.</exception>\n        public EventSubscription(IDelegateReference actionReference, IDelegateReference filterReference)\n        {\n            if (actionReference == null)\n                throw new ArgumentNullException(nameof(actionReference));\n            if (!(actionReference.Target is Action<TPayload>))\n                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidDelegateRerefenceTypeException, typeof(Action<TPayload>).FullName), nameof(actionReference));\n\n            if (filterReference == null)\n                throw new ArgumentNullException(nameof(filterReference));\n            if (!(filterReference.Target is Predicate<TPayload>))\n                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidDelegateRerefenceTypeException, typeof(Predicate<TPayload>).FullName), nameof(filterReference));\n\n            _actionReference = actionReference;\n            _filterReference = filterReference;\n        }\n\n        /// <summary>\n        /// Gets the target <see cref=\"System.Action{T}\"/> that is referenced by the <see cref=\"IDelegateReference\"/>.\n        /// </summary>\n        /// <value>An <see cref=\"System.Action{T}\"/> or <see langword=\"null\" /> if the referenced target is not alive.</value>\n        public Action<TPayload> Action\n        {\n            get { return (Action<TPayload>)_actionReference.Target; }\n        }","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Events/EventSubscription.cs#L90-L126","documentation":"Generic EventSubscription<TPayload> throws ArgumentException formatted from Resources.InvalidDelegateRerefenceTypeException with typeof(Action<TPayload>).FullName when the supplied actionReference's Target is not an Action<TPayload> (a parallel check exists for filterReference with Predicate<TPayload>). It signals a delegate signature mismatch.","triggerScenarios":"Wrapping a parameterless Action, Action<OtherType>, or Func<TPayload,...> in a DelegateReference and passing it as actionReference; swapping generic payload types so the delegate no longer matches.","commonSituations":"Changing an event's payload type without updating subscribers; using a shared DelegateReference across differently-typed events; manually constructing subscription strategies in custom PubSubEvent subclasses.","solutions":["Ensure the delegate is exactly Action<TPayload> for the event's payload type","Recreate the DelegateReference with the correctly typed delegate","Update subscriber signatures after payload type changes"],"exampleFix":"// before\nvar sub = new EventSubscription<Payload>(new DelegateReference((Action)(() => { }), false), filterRef);\n// after\nvar sub = new EventSubscription<Payload>(new DelegateReference((Action<Payload>)(p => { }), false), filterRef);","handlingStrategy":"validation","validationCode":"if (!(actionReference?.Target is Action<Payload>)) throw new InvalidOperationException(\"actionReference must wrap Action<Payload>\");\nvar sub = new EventSubscription<Payload>(actionReference, filterReference);","typeGuard":"bool IsValidActionRef<T>(IDelegateReference r) => r?.Target is Action<T>;","tryCatchPattern":"try { var sub = new EventSubscription<Payload>(actionRef, filterRef); }\ncatch (ArgumentException ex) { log.Error($\"Delegate type mismatch: {ex.Message}\"); }","preventionTips":["Keep DelegateReference payloads aligned with the event's TPayload","After changing a payload type, recreate all DelegateReferences","Prefer the typed Subscribe overload to avoid manual construction errors"],"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"}