{"record":{"id":"d958e079c2d30661","repo":"dotnet/reactive","slug":"source-takelastbuffer","errorCode":null,"errorMessage":"source","messagePattern":"source","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/TakeLastBuffer.cs","lineNumber":16,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nusing System.Collections.Generic;\nusing System.Reactive.Concurrency;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<IList<TSource>> TakeLastBuffer<TSource>(this IAsyncObservable<TSource> source, int count)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (count < 0)\n                throw new ArgumentOutOfRangeException(nameof(count));\n\n            if (count == 0)\n            {\n                return Empty<IList<TSource>>();\n            }\n\n            return CreateAsyncObservable<IList<TSource>>.From(\n                source,\n                count,\n                static (source, count, observer) => source.SubscribeSafeAsync(AsyncObserver.TakeLastBuffer(observer, count)));\n        }\n\n        public static IAsyncObservable<IList<TSource>> TakeLastBuffer<TSource>(this IAsyncObservable<TSource> source, TimeSpan duration)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/TakeLastBuffer.cs#L1-L34","documentation":"TakeLastBuffer(source, count) validates the source observable and throws ArgumentNullException when it is null. As an extension method invoked on a null receiver, the guard fires inside the method rather than at the call site.","triggerScenarios":"source.TakeLastBuffer(10) where source is a null IAsyncObservable<TSource>, e.g. from a builder method that returned null.","commonSituations":"Factory/conditional composition returning null observables; assigning the result of a lookup that found nothing; missing earlier operator validation.","solutions":["Ensure the source observable is created before calling TakeLastBuffer.","Add a null check on the source at its construction point.","Replace null-producing factory branches with a non-null Empty observable."],"exampleFix":"// before\nIAsyncObservable<int> source = Build(); // may be null\nvar buf = source.TakeLastBuffer(10);\n// after\nvar source = Build() ?? AsyncObservable.Empty<int>();\nvar buf = source.TakeLastBuffer(10);","handlingStrategy":"validation","validationCode":"if (source is null) throw new ArgumentNullException(nameof(source));\nsource.TakeLastBuffer(count);","typeGuard":"bool HasSource<TSource>(IAsyncObservable<TSource> s) => s is not null;","tryCatchPattern":"try { var buf = source.TakeLastBuffer(count); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* substitute Empty source */ }","preventionTips":["Coalesce null observables with AsyncObservable.Empty<TSource>().","Ensure factory methods never return null observables.","Enable nullable reference types for compile-time null tracking."],"tags":["argument-null","asyncrx","takelastbuffer","observable"],"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"}