{"record":{"id":"7ee217db552271d9","repo":"dotnet/reactive","slug":"error-asyncsubject","errorCode":null,"errorMessage":"error","messagePattern":"error","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Subjects/AsyncSubject.cs","lineNumber":125,"sourceCode":"                        foreach (var observer in observers)\n                        {\n                            observer.Observer?.OnCompleted();\n                        }\n                    }\n                }\n            }\n        }\n\n        /// <summary>\n        /// Notifies all subscribed observers about the exception.\n        /// </summary>\n        /// <param name=\"error\">The exception to send to all observers.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"error\"/> is <c>null</c>.</exception>\n        public override void OnError(Exception error)\n        {\n            if (error == null)\n            {\n                throw new ArgumentNullException(nameof(error));\n            }\n\n            for (; ; )\n            {\n                var observers = Volatile.Read(ref _observers);\n\n                if (observers == Disposed)\n                {\n                    _exception = null;\n                    _value = default;\n                    ThrowDisposed();\n                    break;\n                }\n\n                if (observers == Terminated)\n                {\n                    break;\n                }","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Subjects/AsyncSubject.cs#L107-L143","documentation":"AsyncSubject.OnError caches and replays the terminal error to all current and future observers; a null error is invalid because subscribers must receive an actual exception, so it is validated. Fix: call OnCompleted instead if the sequence ends without error.","triggerScenarios":"Calling AsyncSubject<T>.OnError(null), often from source wrappers that pass along a null exception from underlying streams.","commonSituations":"Custom IObservable sources forwarding a null Exception from Task.Exception or from event handlers that capture no error.","solutions":["Pass a concrete Exception; wrap unknown failures in a new Exception or OperationCanceledException.","Null-check before calling OnError in source/wrapper code.","Use OnError(new AggregateException(inner)) if aggregating multiple failures."],"exampleFix":"// before\nsubject.OnError(ex); // ex may be null\n// after\nif (ex != null) subject.OnError(ex); else subject.OnError(new InvalidOperationException(\"unknown failure\"));","handlingStrategy":"validation","validationCode":"if (error == null) subject.OnError(new InvalidOperationException(\"source failed without exception\")); else subject.OnError(error);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass null to OnError; wrap unknown failures.","Validate exceptions at the boundary of custom IObservable sources."],"tags":["argument-null","rx","subject"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}