{"record":{"id":"4655ffcd9cdc1947","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-clock","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'clock')","messagePattern":"Value cannot be null\\. \\(Parameter 'clock'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Timestamp.cs","lineNumber":48,"sourceCode":"        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static IAsyncObserver<TSource> Timestamp<TSource>(IAsyncObserver<Timestamped<TSource>> observer)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            return Timestamp(observer, Clock.Default);\n        }\n\n        public static IAsyncObserver<TSource> Timestamp<TSource>(IAsyncObserver<Timestamped<TSource>> observer, IClock clock)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (clock == null)\n                throw new ArgumentNullException(nameof(clock));\n\n            return Select<TSource, Timestamped<TSource>>(observer, x => new Timestamped<TSource>(x, clock.Now));\n        }\n    }\n}\n","sourceCodeStart":30,"sourceCodeEnd":54,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Timestamp.cs#L30-L54","documentation":"AsyncObserver.Timestamp(observer, clock) throws ArgumentNullException with message \"Value cannot be null. (Parameter 'clock')\" when the IClock parameter is null. Each element is stamped with clock.Now, so a null clock would break every notification; the library validates it up front.","triggerScenarios":"Calling AsyncObserver.Timestamp<T>(observer, clock) with clock == null, e.g. an injected test clock that was never registered, or passing null expecting default-clock behavior.","commonSituations":"Simulated-time unit tests where the VirtualTimeClock/TestClock registration is missing; refactor to inject IClock left a null field; passing null intentionally in integration glue code.","solutions":["Use the single-argument overload AsyncObserver.Timestamp(observer), which defaults to Clock.Default.","Pass a concrete IClock such as Clock.Default or the test clock instance.","Fix DI/configuration so IClock resolves to a real instance before operator composition."],"exampleFix":"// before\nvar stamped = AsyncObserver.Timestamp<int>(observer, testClock); // testClock not initialized (null)\n\n// after\ntestClock ??= new TestClock();\nvar stamped = AsyncObserver.Timestamp<int>(observer, testClock);","handlingStrategy":"validation","validationCode":"if (clock is null)\n    throw new InvalidOperationException(\"IClock must be provided; use Clock.Default or a test clock.\");","typeGuard":"bool HasClock(IClock? clock) => clock is not null;","tryCatchPattern":"try\n{\n    return AsyncObserver.Timestamp(observer, clock);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"clock\")\n{\n    return AsyncObserver.Timestamp(observer); // default clock\n}","preventionTips":["Default the clock with ?? Clock.Default before composing.","Never pass null to signal 'use default'; call the parameterless overload instead.","Verify test-clock registration in test fixtures' setup phase."],"tags":["csharp","asyncrx","argument-validation","null-check","clock"],"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"}