PrismLibrary/Prism · error · ArgumentNullException
ArgumentNullException(nameof(actionReference))
Error message
ArgumentNullException(nameof(actionReference))
What it means
The non-generic EventSubscription constructor stores an IDelegateReference that must wrap a System.Action. It throws ArgumentNullException when actionReference is null and ArgumentException (Resources.InvalidDelegateRerefenceTypeException) when the reference's Target is not an Action.
Solutions
- Pass a DelegateReference whose Target is a System.Action
- Verify the delegate type before creating the DelegateReference
- Use the public PubSubEvent.Subscribe API instead of constructing EventSubscription manually
Example fix
// before
var sub = new EventSubscription(new DelegateReference((Func<int>)() => 1, false));
// after
var sub = new EventSubscription(new DelegateReference((Action)(() => { }), false)); Defensive patterns
Strategy: validation
Validate before calling
if (actionReference?.Target is Action) { var sub = new EventSubscription(actionReference); } Type guard
bool IsValidActionRef(IDelegateReference r) => r?.Target is Action;
Try / catch
try { var sub = new EventSubscription(actionRef); }
catch (ArgumentException ex) { log.Error($"actionReference target must be Action: {ex.Message}"); }
catch (ArgumentNullException) { log.Error("actionReference was null"); } Prevention
- Wrap parameterless System.Action delegates only
- Prefer the public Subscribe API over manual EventSubscription construction
When it happens
Trigger: new EventSubscription(null); or new EventSubscription(new DelegateReference(someFuncOrNonActionDelegate, false)) where the wrapped target is a Func, Predicate, or custom delegate rather than Action.
Common situations: Building custom PubSubEvent subscription internals; passing a DelegateReference created for a differently-typed delegate after refactoring the event payload/signature.
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
- ArgumentNullException("delegate")
- Resources.InvalidDelegateRerefenceTypeException (formatted…
- Resources.InvalidDelegateRerefenceTypeException (formatted…
- ArgumentNullException(nameof(eventSubscription))
- ArgumentNullException(nameof(action))
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/1bb6214175710b62.
Report an issue: GitHub.
Appendix: source
Thrown at src/Prism.Events/EventSubscription.cs:24
{
/// <summary>
/// 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>View on GitHub (pinned to 358118cd64)