{"record":{"id":"90cda21a2a3a3e4c","repo":"AvaloniaUI/Avalonia","slug":"value-cannot-be-null-parameter-onnext","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'onNext')","messagePattern":"Value cannot be null\\. \\(Parameter 'onNext'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Reactive/AnonymousObserver.cs","lineNumber":31,"sourceCode":"    private readonly Action<T> _onNext;\n    private readonly Action<Exception> _onError;\n    private readonly Action _onCompleted;\n\n    public AnonymousObserver(TaskCompletionSource<T> tcs)\n    {\n        if (tcs is null)\n        {\n            throw new ArgumentNullException(nameof(tcs));\n        }\n\n        _onNext = tcs.SetResult;\n        _onError = tcs.SetException;\n        _onCompleted = NoOpCompleted;\n    }\n    \n    public AnonymousObserver(Action<T> onNext, Action<Exception> onError, Action onCompleted)\n    {\n        _onNext = onNext ?? throw new ArgumentNullException(nameof(onNext));\n        _onError = onError ?? throw new ArgumentNullException(nameof(onError));\n        _onCompleted = onCompleted ?? throw new ArgumentNullException(nameof(onCompleted));\n    }\n\n    public AnonymousObserver(Action<T> onNext)\n        : this(onNext, ThrowsOnError, NoOpCompleted)\n    {\n    }\n\n    public AnonymousObserver(Action<T> onNext, Action<Exception> onError)\n        : this(onNext, onError, NoOpCompleted)\n    {\n    }\n\n    public AnonymousObserver(Action<T> onNext, Action onCompleted)\n        : this(onNext, ThrowsOnError, onCompleted)\n    {\n    }","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Reactive/AnonymousObserver.cs#L13-L49","documentation":"AnonymousObserver<T>(Action<T> onNext, Action<Exception> onError, Action onCompleted) stores three callbacks; onNext is required and throws ArgumentNullException(nameof(onNext)) when null via the inline `?? throw`. Without an OnNext handler the observer is meaningless, so null is rejected at construction.","triggerScenarios":"Constructing AnonymousObserver<T> with a null first-argument Action<T>, or via the single/overload chain that forwards into this constructor.","commonSituations":"Building an observer from method-group or lambda variables where the onNext delegate was never assigned, or was set to a null delegate field.","solutions":["Provide a non-null Action<T> as the onNext handler.","Null-check delegate fields before constructing the observer, and skip subscription when null.","Use a no-op (e.g. _ => { }) if you genuinely want to ignore items but still need the observer shape."],"exampleFix":"// before\nAction<T> onNext = null;\nsource.Subscribe(new AnonymousObserver<T>(onNext, onError, onDone)); // throws\n\n// after\nsource.Subscribe(new AnonymousObserver<T>(x => Consume(x), onError, onDone));","handlingStrategy":"validation","validationCode":"if (onNext is null) return;\nsource.Subscribe(new AnonymousObserver<T>(onNext, onError, onCompleted));","typeGuard":"bool HasOnNext<T>(Action<T>? a) => a is not null;","tryCatchPattern":null,"preventionTips":["Pass a concrete non-null OnNext lambda.","If ignoring items is intended, use a no-op _ => { }.","Null-check delegate fields from computed sources."],"tags":["avalonia","reactive","observer","argumentnull","callback"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}