PrismLibrary/Prism · error · ArgumentNullException
Value cannot be null. (Parameter 'onNext')
Error message
Value cannot be null. (Parameter 'onNext')
What it means
Prism's ObservableExtensions.Subscribe extension validates the onNext callback and throws ArgumentNullException(nameof(onNext)) when the Action<T> delegate passed is null. Subscribing without a handler action is not allowed.
Solutions
- Pass a valid Action<T> callback to Subscribe, or use an empty lambda _ => { } if no action is needed.
- Guard with onNext != null before calling Subscribe if the handler comes from external configuration.
- Verify the delegate field/property holding the handler is assigned before subscription.
Example fix
// before stream.Subscribe(_handler); // _handler is null // after stream.Subscribe(value => Handle(value));
Defensive patterns
Strategy: validation
Validate before calling
if (onNext is null) throw new InvalidOperationException("Subscribe requires an onNext handler");
source.Subscribe(onNext); Try / catch
try { stream.Subscribe(handler); }
catch (ArgumentNullException ex) when (ex.ParamName == "onNext") { /* handler not configured */ } Prevention
- Never store handlers in fields that may be null at subscription time
- Use a no-op lambda (_ => { }) when no action is required
- Resolve handler delegates before wiring subscriptions
When it happens
Trigger: Passing a null Action<T> to source.Subscribe(onNext) — e.g. a method reference that is null, a conditionally assigned handler field, or reflection-built delegate that failed to resolve.
Common situations: Handler assigned from configuration or DI that wasn't set; passing a variable that's null on some code path; copy-pasting Subscribe overloads and accidentally dropping the lambda.
Related errors
- Value cannot be null. (Parameter 'source')
- ArgumentNullException for 'view'
- At least one button needs to be supplied
- IModuleCatalog
- navigationCallback
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/81c8f211a07c5867.
Report an issue: GitHub.
Appendix: source
Thrown at src/Avalonia/Prism.Avalonia/Extensions/ObservableExtensions.cs:26
{
/// <summary>
/// Subscribes an element handler to an observable sequence.
/// </summary>
/// <typeparam name="T">The type of the elements in the source sequence.</typeparam>
/// <param name="source">Observable sequence to subscribe to.</param>
/// <param name="onNext">Action to invoke for each element in the observable sequence.</param>
/// <returns><see cref="IDisposable"/> object used to unsubscribe from the observable sequence.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="onNext"/> is <c>null</c>.</exception>
public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
if (onNext == null)
{
throw new ArgumentNullException(nameof(onNext));
}
//
// [OK] Use of unsafe Subscribe: non-pretentious constructor for an observer; this overload is not to be used internally.
//
return source.Subscribe/*Unsafe*/(new AnonymousObserver<T>(onNext, Stubs.Throw, Stubs.Nop));
}
}
}
View on GitHub (pinned to 358118cd64)