{"record":{"id":"d463638ba5f6847d","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-actual","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'actual')","messagePattern":"Value cannot be null\\. \\(Parameter 'actual'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveAssert.cs","lineNumber":194,"sourceCode":"        /// <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        {\n            if (action == null)\n            {\n                throw new ArgumentNullException(nameof(action));\n            }\n","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveAssert.cs#L176-L212","documentation":"ReactiveAssert.AreElementsEqual(expected, actual, comparer, message) throws ArgumentNullException with parameter name 'actual' when the actual IObservable<T> is null. The expected argument is validated first, so hitting this means expected was fine but the observed sequence was null.","triggerScenarios":"Calling AreElementsEqual with null actual observable — typically the observable under test returned null (e.g. a stub or factory returning null instead of Observable.Empty).","commonSituations":"Mocked dependencies configured without a Return value; async factory methods that can return null; tests written before the system under test was wired up.","solutions":["Ensure the code under test returns a real observable (use Observable.Empty<T>() instead of null).","Fix mock/stub setup so the tested path returns an observable.","Check for null and fail with a clearer test assertion before calling AreElementsEqual."],"exampleFix":"// before\nvar actual = _sut.GetStream(); // returns null\nReactiveAssert.AreElementsEqual(expected, actual, comparer);\n// after\nAssert.NotNull(_sut.GetStream);\nvar actual = _sut.GetStream() ?? Observable.Empty<int>();\nReactiveAssert.AreElementsEqual(expected, actual, comparer);","handlingStrategy":"validation","validationCode":"if (actual == null)\n    throw new InvalidOperationException(\"Observable under test returned null\");\nReactiveAssert.AreElementsEqual(expected, actual, comparer);","typeGuard":"if (actual is not IObservable<int> validActual) Assert.Fail(\"actual is null or wrong type\");","tryCatchPattern":"try\n{\n    ReactiveAssert.AreElementsEqual(expected, actual, comparer);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"actual\")\n{\n    Assert.Fail(\"SUT returned null observable — check stubs/factory\");\n}","preventionTips":["Configure mocks to return Observable.Empty<T>() as default.","Make SUT methods guarantee non-null observable returns.","Use Assert.NotNull on SUT results before sequence comparison.","Cover null-return code paths with dedicated tests."],"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"}