dotnet/reactive · error · ArgumentNullException

Value cannot be null. (Parameter 'bufferBoundaries')

Error message

Value cannot be null. (Parameter 'bufferBoundaries')

What it means

The Buffer(source, bufferBoundaries) overload throws ArgumentNullException when the bufferBoundaries observable is null. The boundaries stream supplies the delimiters between buffers, so it is a required argument validated synchronously at the call site.

Solutions

  1. Initialize or fix the boundary observable before the call.
  2. Use Observable.Empty<TBufferBoundary>() (or Observable.Never<TBufferBoundary>()) when no boundaries should exist — Empty closes one final buffer, Never keeps the current buffer open.
  3. Guard the call site so Buffer is only invoked with a non-null boundaries stream.

Example fix

// before
var buffers = source.Buffer(maybeBoundaries); // throws if maybeBoundaries is null
// after
var boundaries = maybeBoundaries ?? Observable.Never<long>();
var buffers = source.Buffer(boundaries);
Defensive patterns

Strategy: validation

Validate before calling

ArgumentNullException.ThrowIfNull(boundaries);
var boundaries = maybeBoundaries ?? Observable.Never<TBufferBoundary>();

Type guard

bool HasBoundaries<TBufferBoundary>(IObservable<TBufferBoundary>? b) => b is not null;

Try / catch

try { var buffers = source.Buffer(boundaries); }
catch (ArgumentNullException ex) when (ex.ParamName == "bufferBoundaries") { /* supply Observable.Never<TBufferBoundary>() */ }

Prevention

When it happens

Trigger: Calling source.Buffer(boundaries) where the boundaries IObservable<TBufferBoundary> is null — e.g. a timer/tick stream never started, a merged boundary stream built from possibly-null inputs, or a null returned by a boundary-stream factory.

Common situations: Combining several boundary streams with a helper that returns null when all inputs are absent; event-driven boundary streams not yet wired (null field); config-driven boundary source missing so the factory returns null.

Related errors


AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15). Data as JSON: /api/errors/6d644cb048786521. Report an issue: GitHub.

Appendix: source

Thrown at Rx.NET/Source/src/System.Reactive/Linq/Observable.Multiple.cs:153

        /// <summary>
        /// Projects each element of an observable sequence into consecutive non-overlapping buffers.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements in the source sequence, and in the lists in the result sequence.</typeparam>
        /// <typeparam name="TBufferBoundary">The type of the elements in the sequences indicating buffer boundary events.</typeparam>
        /// <param name="source">Source sequence to produce buffers over.</param>
        /// <param name="bufferBoundaries">Sequence of buffer boundary markers. The current buffer is closed and a new buffer is opened upon receiving a boundary marker.</param>
        /// <returns>An observable sequence of buffers.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="bufferBoundaries"/> is null.</exception>
        public static IObservable<IList<TSource>> Buffer<TSource, TBufferBoundary>(this IObservable<TSource> source, IObservable<TBufferBoundary> bufferBoundaries)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (bufferBoundaries == null)
            {
                throw new ArgumentNullException(nameof(bufferBoundaries));
            }

            return s_impl.Buffer(source, bufferBoundaries);
        }

        #endregion

        #region + Catch +

        /// <summary>
        /// Continues an observable sequence that is terminated by an exception of the specified type with the observable sequence produced by the handler.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements in the source sequence and sequences returned by the exception handler function.</typeparam>
        /// <typeparam name="TException">The type of the exception to catch and handle. Needs to derive from <see cref="Exception"/>.</typeparam>
        /// <param name="source">Source sequence.</param>
        /// <param name="handler">Exception handler function, producing another observable sequence.</param>
        /// <returns>An observable sequence containing the source sequence's elements, followed by the elements produced by the handler's resulting observable sequence in case an exception occurred.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="handler"/> is null.</exception>

View on GitHub (pinned to 94b5d5ab91)