{"record":{"id":"90b6bc38672f4725","repo":"dotnet/reactive","slug":"sampler","errorCode":null,"errorMessage":"sampler","messagePattern":"sampler","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":915,"sourceCode":"        /// Samples the source observable sequence using a sampler observable sequence producing sampling ticks.\n        /// Upon each sampling tick, the latest element (if any) in the source sequence during the last sampling interval is sent to the resulting sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TSample\">The type of the elements in the sampling sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to sample.</param>\n        /// <param name=\"sampler\">Sampling tick sequence.</param>\n        /// <returns>Sampled observable sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"sampler\"/> is null.</exception>\n        public static IObservable<TSource> Sample<TSource, TSample>(this IObservable<TSource> source, IObservable<TSample> sampler)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (sampler == null)\n            {\n                throw new ArgumentNullException(nameof(sampler));\n            }\n\n            return s_impl.Sample(source, sampler);\n        }\n\n        #endregion\n\n        #region + Skip +\n\n        /// <summary>\n        /// Skips elements for the specified duration from the start of the observable source sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to skip elements for.</param>\n        /// <param name=\"duration\">Duration for skipping elements from the start of the sequence.</param>\n        /// <returns>An observable sequence with the elements skipped during the specified duration from the start of the source sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is null.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"duration\"/> is less than TimeSpan.Zero.</exception>","sourceCodeStart":897,"sourceCodeEnd":933,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L897-L933","documentation":"The sampler overload Sample<TSource, TSample>(IObservable<TSource>, IObservable<TSample>) throws ArgumentNullException when the sampler observable is null. The sampler drives emission of the latest source value, so it must be a valid observable.","triggerScenarios":"Calling source.Sample(null) or Observable.Sample(source, (IObservable<TSample>)null) — a null sampler, often from an unassigned signal stream or a failed lookup of the sampler sequence.","commonSituations":"A 'trigger' stream field never initialized; an event-to-observable conversion that returned null; mistaking the overload set and passing null where a TimeSpan was expected is a compile error, so this occurs with dynamic/reflective composition or DI.","solutions":["Ensure the sampler observable is created and assigned before the Sample call.","Guard: if sampler == null, decide whether to use the time-based overload Sample(source, interval) instead.","Fix the producer of the sampler so it never returns null (use Observable.Never<TSample>() as a do-nothing sampler)."],"exampleFix":"// before\nvar result = source.Sample(sampler); // sampler is null\n\n// after\nvar result = source.Sample(sampler ?? Observable.Never<Unit>());","handlingStrategy":"validation","validationCode":"if (sampler == null)\n    sampler = Observable.Never<TSample>(); // no samples will be emitted\nvar result = source.Sample(sampler);","typeGuard":"static bool HasValidSampler<TSource, TSample>(IObservable<TSource> source, IObservable<TSample> sampler) =>\n    source != null && sampler != null;","tryCatchPattern":"try\n{\n    var result = source.Sample(sampler);\n}\ncatch (ArgumentNullException)\n{\n    var result = source.Sample(TimeSpan.FromSeconds(1)); // fall back to time-based sampling\n}","preventionTips":["Use Observable.Never<T>() as the null-object for an optional sampler.","Verify trigger/signal streams are created before they are consumed.","When wiring event-based samplers, confirm the conversion (FromEventPattern) succeeded."],"tags":["argument-null","rx","sample","sampler"],"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"}