{"record":{"id":"0c42e4987b5a2755","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-expected","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'expected')","messagePattern":"Value cannot be null\\. \\(Parameter 'expected'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveAssert.cs","lineNumber":189,"sourceCode":"            }\n\n            AreElementsEqual(expected.Materialize().ToEnumerable(), actual.Materialize().ToEnumerable(), message);\n        }\n\n        /// <summary>\n        /// Asserts that both observable sequences have equal length and equal elements.\n        /// </summary>\n        /// <typeparam name=\"T\">The type of the elements in the sequence.</typeparam>\n        /// <param name=\"expected\">Expected sequence.</param>\n        /// <param name=\"actual\">Actual sequence to compare against the expected one.</param>\n        /// <param name=\"comparer\">Comparer used to check for equality.</param>\n        /// <param name=\"message\">Error message for assert failure.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"expected\"/> or <paramref name=\"actual\"/> is null.</exception>\n        public static void AreElementsEqual<T>(IObservable<T> expected, IObservable<T> actual, IEqualityComparer<T> comparer, string message)\n        {\n            if (expected == null)\n            {\n                throw new ArgumentNullException(nameof(expected));\n            }\n\n            if (actual == null)\n            {\n                throw new ArgumentNullException(nameof(actual));\n            }\n\n            AreElementsEqual(expected.Materialize().ToEnumerable(), actual.Materialize().ToEnumerable(), new NotificationComparer<T>(comparer), message);\n        }\n\n        /// <summary>\n        /// Asserts that the given action throws an exception of the type specified in the generic parameter, or a subtype thereof.\n        /// </summary>\n        /// <typeparam name=\"TException\">Type of the exception to check for.</typeparam>\n        /// <param name=\"action\">Action to run.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"action\"/> is null.</exception>\n        public static void Throws<TException>(Action action) where TException : Exception\n        {","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveAssert.cs#L171-L207","documentation":"ReactiveAssert.AreElementsEqual(expected, actual, comparer, message) throws ArgumentNullException with parameter name 'expected' when the expected IObservable<T> is null. This is an upfront argument validation in the Rx testing helper before comparing materialized notifications.","triggerScenarios":"Calling ReactiveAssert.AreElementsEqual with a null expected observable, e.g. a test fixture returning null because a service/factory failed silently.","commonSituations":"Unit tests where the 'expected' hot/cold observable was never assigned, a mock returned null instead of a scheduler-created observable, or refactored test helpers broke observable creation.","solutions":["Fix the test to pass a non-null expected observable (e.g. scheduler.CreateColdObservable(...) or Observable.Range(...)).","Guard the code that produces the expected sequence so it never yields null.","If null is a legitimate outcome, assert null-ness separately instead of calling AreElementsEqual."],"exampleFix":"// before\nIObservable<int> expected = MaybeCreate();\nReactiveAssert.AreElementsEqual(expected, actual, comparer, \"msg\");\n// after\nIObservable<int> expected = MaybeCreate() ?? Observable.Empty<int>();\nReactiveAssert.AreElementsEqual(expected, actual, comparer, \"msg\");","handlingStrategy":"validation","validationCode":"if (expected == null)\n    throw new InvalidOperationException(\"Test misconfigured: expected observable is null\");\nReactiveAssert.AreElementsEqual(expected, actual, comparer, \"msg\");","typeGuard":"bool ok = expected is IObservable<int> nonNull;\nif (!ok) failFast();","tryCatchPattern":"try\n{\n    ReactiveAssert.AreElementsEqual(expected, actual, comparer, \"sequences differ\");\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"expected\")\n{\n    Assert.Fail(\"Expected observable was null — fixture setup bug\");\n}","preventionTips":["Create observables via scheduler helpers (CreateColdObservable/CreateHotObservable) instead of nullable fields.","Initialize expected sequences in test setup, not lazily.","Never let factories return null observables; return Observable.Empty instead.","Assert fixture setup succeeded before running sequence assertions."],"tags":["testing","rx","null-check","assert"],"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"}