PrismLibrary/Prism · error · ArgumentException

Resources.InvalidDelegateRerefenceTypeException (formatted…

Error message

Resources.InvalidDelegateRerefenceTypeException (formatted with typeof(Action).FullName)

What it means

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.

Solutions

  1. Ensure the delegate referenced is exactly System.Action (parameterless)
  2. Change the handler signature to match Action
  3. Use EventSubscription<TPayload> with Action<TPayload> when the handler takes a payload

Example fix

// before
var sub = new EventSubscription(new DelegateReference((Action<object>)(o => { }), false));
// after
var sub = new EventSubscription(new DelegateReference((Action)(() => { }), false));
Defensive patterns

Strategy: validation

Validate before calling

if (!(actionReference?.Target is Action)) throw new InvalidOperationException("DelegateReference must wrap a parameterless Action");

Type guard

bool IsActionRef(IDelegateReference r) => r?.Target is Action;

Try / catch

try { var sub = new EventSubscription(actionRef); }
catch (ArgumentException ex) { log.Error($"Wrong delegate type for action: {ex.Message}"); }

Prevention

When it happens

Trigger: Creating an EventSubscription whose actionReference wraps a Func<T>, Action with parameters, Predicate, or any delegate that fails the 'is Action' pattern test.

Common situations: 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.

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


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/4a54829adea26846. Report an issue: GitHub.

Appendix: source

Thrown at src/Prism.Events/EventSubscription.cs:26

    /// Provides a way to retrieve a <see cref="Delegate"/> to execute an action depending
    /// on the value of a second filter predicate that returns true if the action should execute.
    /// </summary>
    public class EventSubscription : IEventSubscription
    {
        private readonly IDelegateReference _actionReference;

        ///<summary>
        /// Creates a new instance of <see cref="EventSubscription"/>.
        ///</summary>
        ///<param name="actionReference">A reference to a delegate of type <see cref="System.Action"/>.</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"/>.</exception>
        public EventSubscription(IDelegateReference actionReference)
        {
            if (actionReference == null)
                throw new ArgumentNullException(nameof(actionReference));
            if (!(actionReference.Target is Action))
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidDelegateRerefenceTypeException, typeof(Action).FullName), nameof(actionReference));

            _actionReference = actionReference;
        }

        /// <summary>
        /// Gets the target <see cref="System.Action"/> that is referenced by the <see cref="IDelegateReference"/>.
        /// </summary>
        /// <value>An <see cref="System.Action"/> or <see langword="null" /> if the referenced target is not alive.</value>
        public Action Action
        {
            get { return (Action)_actionReference.Target; }
        }

        /// <summary>
        /// Gets or sets a <see cref="SubscriptionToken"/> that identifies this <see cref="IEventSubscription"/>.
        /// </summary>
        /// <value>A token that identifies this <see cref="IEventSubscription"/>.</value>
        public SubscriptionToken SubscriptionToken { get; set; }

View on GitHub (pinned to 358118cd64)