{"record":{"id":"f1164244a445a050","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-messages","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'messages')","messagePattern":"Value cannot be null\\. \\(Parameter 'messages'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/Microsoft.Reactive.Testing/TestScheduler.cs","lineNumber":161,"sourceCode":"            {\n                throw new ArgumentNullException(nameof(create));\n            }\n\n            return Start(create, ReactiveTest.Created, ReactiveTest.Subscribed, ReactiveTest.Disposed);\n        }\n\n        /// <summary>\n        /// Creates a hot observable using the specified timestamped notification messages.\n        /// </summary>\n        /// <typeparam name=\"T\">The element type of the observable sequence being created.</typeparam>\n        /// <param name=\"messages\">Notifications to surface through the created sequence at their specified absolute virtual times.</param>\n        /// <returns>Hot observable sequence that can be used to assert the timing of subscriptions and notifications.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"messages\"/> is null.</exception>\n        public ITestableObservable<T> CreateHotObservable<T>(params Recorded<Notification<T>>[] messages)\n        {\n            if (messages == null)\n            {\n                throw new ArgumentNullException(nameof(messages));\n            }\n\n            return new HotObservable<T>(this, messages);\n        }\n\n        /// <summary>\n        /// Creates a cold observable using the specified timestamped notification messages.\n        /// </summary>\n        /// <typeparam name=\"T\">The element type of the observable sequence being created.</typeparam>\n        /// <param name=\"messages\">Notifications to surface through the created sequence at their specified virtual time offsets from the sequence subscription time.</param>\n        /// <returns>Cold observable sequence that can be used to assert the timing of subscriptions and notifications.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"messages\"/> is null.</exception>\n        public ITestableObservable<T> CreateColdObservable<T>(params Recorded<Notification<T>>[] messages)\n        {\n            if (messages == null)\n            {\n                throw new ArgumentNullException(nameof(messages));\n            }","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/Microsoft.Reactive.Testing/TestScheduler.cs#L143-L179","documentation":"TestScheduler.CreateHotObservable throws ArgumentNullException when the messages array parameter is null. It builds a HotObservable that replays Recorded<Notification<T>> marble messages; a null message list cannot represent a valid sequence, so it is rejected before construction. Note an empty array is allowed (a hot observable that never emits).","triggerScenarios":"Calling scheduler.CreateHotObservable<T>(null) explicitly, or passing a Recorded<Notification<T>>[] variable that is null (e.g. from a failed lookup or deserialization), while an empty params list is fine.","commonSituations":"Marble-test helpers that build message arrays dynamically and return null on parse failure; data-driven tests with null entries; refactors converting marble-string parsers to array builders that leave null results.","solutions":["Pass at least an empty array instead of null: CreateHotObservable<int>()","Fix the array-producing helper to return Array.Empty<Recorded<Notification<int>>>() when there are no messages","Null-check parsed marble input before constructing the observable"],"exampleFix":"// before\nvar xs = scheduler.CreateHotObservable<int>(ParseMarbles(null)); // null array\n// after\nvar msgs = ParseMarbles(marbleString) ?? Array.Empty<Recorded<Notification<int>>>();\nvar xs = scheduler.CreateHotObservable(msgs);","handlingStrategy":"validation","validationCode":"// C#\nRecorded<Notification<int>>[]? msgs = BuildMessages(marble);\nif (msgs is null)\n    msgs = Array.Empty<Recorded<Notification<int>>>();\nvar xs = scheduler.CreateHotObservable(msgs);","typeGuard":"bool HasMessages<T>(Recorded<Notification<T>>[]? m) => m is not null;","tryCatchPattern":"try { var xs = scheduler.CreateHotObservable(msgs); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"messages\")\n{\n    xs = scheduler.CreateHotObservable<T>(); // empty hot observable\n}","preventionTips":["Call CreateHotObservable<T>() with no args instead of null for empty sequences","Ensure marble-string parsers return Array.Empty rather than null","Non-nullable array types in test helpers"],"tags":["rx","testscheduler","hot-observable","null-argument"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}