SignalR/SignalR · error · ArgumentNullException
onData
Error message
onData
What it means
HubProxyExtensions.On throws ArgumentNullException('onData') when the callback Action is null. The subscription wraps onData and invokes it per event payload, so a null handler is meaningless and would NRE later — the guard fails fast.
Source
Thrown at src/Microsoft.AspNet.SignalR.Client/HubProxyExtensions.cs:63
/// <param name="proxy">The <see cref="IHubProxy"/>.</param>
/// <param name="eventName">The name of the event.</param>
/// <param name="onData">The callback</param>
/// <returns>An <see cref="IDisposable"/> that represents this subscription.</returns>
public static IDisposable On(this IHubProxy proxy, string eventName, Action onData)
{
if (proxy == null)
{
throw new ArgumentNullException("proxy");
}
if (String.IsNullOrEmpty(eventName))
{
throw new ArgumentNullException("eventName");
}
if (onData == null)
{
throw new ArgumentNullException("onData");
}
Subscription subscription = proxy.Subscribe(eventName);
Action<IList<JToken>> handler = args =>
{
ExecuteCallback(eventName, args.Count, 0, onData);
};
subscription.Received += handler;
return new DisposableAction(() => subscription.Received -= handler);
}
/// <summary>
/// Registers for an event with the specified name and callback
/// </summary>
/// <param name="proxy">The <see cref="IHubProxy"/>.</param>View on GitHub (pinned to 693053b89a)
Solutions
- Always pass a concrete Action; use () => { } as a no-op if you only need side-effect-free subscription.
- If the handler comes from a factory, validate it is non-null before subscribing.
- Prefer method-group references over nullable delegate fields.
Example fix
// before
proxy.On("ping", null);
// after
proxy.On("ping", () => HandlePing()); Defensive patterns
Strategy: validation
Validate before calling
if (onData == null) throw new ArgumentNullException(nameof(onData)); proxy.On(eventName, onData);
Type guard
static bool HasHandler(Action h) => h != null;
Prevention
- Always pass a concrete Action; use () => { } as an explicit no-op.
- Validate factory-produced handlers before subscribing.
- Prefer method-group references over nullable delegate fields.
When it happens
Trigger: Passing null as the callback; handler resolved from a factory that returned null; conditional handler assignment that skipped the real lambda.
Common situations: Refactor left the handler unassigned; DI/factory returned null; copy-paste dropped the lambda body.
Related errors
AI-assisted analysis of SignalR/SignalR@693053b89a (2026-08-13).
Data as JSON: /api/errors/176f758316dcd098.
Report an issue: GitHub.