{"record":{"id":"6cae13b139d0d972","repo":"dotnet/reactive","slug":"observer-max","errorCode":null,"errorMessage":"observer","messagePattern":"observer","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Max.cs","lineNumber":143,"sourceCode":"                async () =>\n                {\n                    if (!found)\n                    {\n                        await observer.OnErrorAsync(new InvalidOperationException(\"The sequence is empty.\")).ConfigureAwait(false);\n                    }\n                    else\n                    {\n                        await observer.OnNextAsync(max).ConfigureAwait(false);\n                        await observer.OnCompletedAsync().ConfigureAwait(false);\n                    }\n                }\n            );\n        }\n\n        public static IAsyncObserver<long> MaxInt64(IAsyncObserver<long> observer)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            var max = 0L;\n            var found = false;\n\n            return Create<long>(\n                x =>\n                {\n                    if (found)\n                    {\n                        if (x > max)\n                        {\n                            max = x;\n                        }\n                    }\n                    else\n                    {\n                        max = x;\n                        found = true;","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Max.cs#L125-L161","documentation":"AsyncObserver.MaxInt64 throws ArgumentNullException with the message 'observer' when the IAsyncObserver<long> argument is null. Like the other typed Max observer factories, it validates its observer argument before building the running-maximum state machine, throwing synchronously at call time.","triggerScenarios":"Calling AsyncObserver.MaxInt64(null) — typically a null forwarded from a custom operator or an observer variable that was never initialized.","commonSituations":"Long-typed aggregation in custom operators where the downstream observer construction was skipped; tests passing null; generic plumbing that erases the observer via a nullable variable.","solutions":["Supply a real IAsyncObserver<long> (AsyncObserver.Create<long>(...) or the pipeline's downstream observer).","Add a null guard in your wrapper so the failure points at the real bug.","Check upstream factories (Select/Where on long streams) for null returns."],"exampleFix":"// before\nvar obs = AsyncObserver.MaxInt64(observer); // null\n\n// after\nvar downstream = AsyncObserver.Create<long>(onNext, onError, onCompleted);\nvar obs = AsyncObserver.MaxInt64(downstream);","handlingStrategy":"validation","validationCode":"if (observer is null) throw new InvalidOperationException(\"MaxInt64 requires a downstream observer\");","typeGuard":"static bool HasLongObserver(IAsyncObserver<long>? o) => o is not null;","tryCatchPattern":"try { var obs = AsyncObserver.MaxInt64(observer); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"observer\") { /* reconstruct observer */ }","preventionTips":["Initialize observer variables at declaration","Use AsyncObserver.Create<long> in tests instead of null doubles","Validate observer arguments in wrapper operator entry points"],"tags":["dotnet","null-argument","asyncrx","maxint64"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}