PrismLibrary/Prism · error · ArgumentException
Resources.InvalidDelegateRerefenceTypeException (formatted…
Error message
Resources.InvalidDelegateRerefenceTypeException (formatted with typeof(Action<TPayload>).FullName)
What it means
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.
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
Example fix
// before
var sub = new EventSubscription<Payload>(new DelegateReference((Action)(() => { }), false), filterRef);
// after
var sub = new EventSubscription<Payload>(new DelegateReference((Action<Payload>)(p => { }), false), filterRef); Defensive patterns
Strategy: validation
Validate before calling
if (!(actionReference?.Target is Action<Payload>)) throw new InvalidOperationException("actionReference must wrap Action<Payload>");
var sub = new EventSubscription<Payload>(actionReference, filterReference); Type guard
bool IsValidActionRef<T>(IDelegateReference r) => r?.Target is Action<T>;
Try / catch
try { var sub = new EventSubscription<Payload>(actionRef, filterRef); }
catch (ArgumentException ex) { log.Error($"Delegate type mismatch: {ex.Message}"); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Resources.InvalidDelegateRerefenceTypeException (formatted…
- ArgumentNullException(nameof(actionReference))
- ArgumentNullException("delegate")
- Resources.InvalidDelegateRerefenceTypeException (formatted…
- Prism applications only support the use of PrismWindow, but…
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/365b7af71bcbe1db.
Report an issue: GitHub.
Appendix: source
Thrown at src/Prism.Events/EventSubscription.cs:108
public class EventSubscription<TPayload> : IEventSubscription
{
private readonly IDelegateReference _actionReference;
private readonly IDelegateReference _filterReference;
///<summary>
/// Creates a new instance of <see cref="EventSubscription{TPayload}"/>.
///</summary>
///<param name="actionReference">A reference to a delegate of type <see cref="System.Action{TPayload}"/>.</param>
///<param name="filterReference">A reference to a delegate of type <see cref="Predicate{TPayload}"/>.</param>
///<exception cref="ArgumentNullException">When <paramref name="actionReference"/> or <see paramref="filterReference"/> are <see langword="null" />.</exception>
///<exception cref="ArgumentException">When the target of <paramref name="actionReference"/> is not of type <see cref="System.Action{TPayload}"/>,
///or the target of <paramref name="filterReference"/> is not of type <see cref="Predicate{TPayload}"/>.</exception>
public EventSubscription(IDelegateReference actionReference, IDelegateReference filterReference)
{
if (actionReference == null)
throw new ArgumentNullException(nameof(actionReference));
if (!(actionReference.Target is Action<TPayload>))
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidDelegateRerefenceTypeException, typeof(Action<TPayload>).FullName), nameof(actionReference));
if (filterReference == null)
throw new ArgumentNullException(nameof(filterReference));
if (!(filterReference.Target is Predicate<TPayload>))
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidDelegateRerefenceTypeException, typeof(Predicate<TPayload>).FullName), nameof(filterReference));
_actionReference = actionReference;
_filterReference = filterReference;
}
/// <summary>
/// Gets the target <see cref="System.Action{T}"/> that is referenced by the <see cref="IDelegateReference"/>.
/// </summary>
/// <value>An <see cref="System.Action{T}"/> or <see langword="null" /> if the referenced target is not alive.</value>
public Action<TPayload> Action
{
get { return (Action<TPayload>)_actionReference.Target; }
}View on GitHub (pinned to 358118cd64)