{"record":{"id":"5c2cb79d05fb2ddd","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-action-reactiveassert","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'action')","messagePattern":"Value cannot be null\\. \\(Parameter 'action'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveAssert.cs","lineNumber":210,"sourceCode":"            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\n            var failed = false;\n            try\n            {\n                action();\n                failed = true;\n            }\n            catch (TException)\n            {\n            }\n            catch (Exception ex)\n            {\n                Assert.True(false, string.Format(CultureInfo.CurrentCulture, \"Expected {0} threw {1}.\\r\\n\\r\\nStack trace:\\r\\n{2}\", typeof(TException).Name, ex.GetType().Name, ex.StackTrace));\n            }\n\n            if (failed)\n            {","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveAssert.cs#L192-L228","documentation":"ReactiveAssert.Throws<TException>(action) throws ArgumentNullException with parameter name 'action' when the delegate to execute is null. The helper needs a callable Action to run and observe whether it throws TException.","triggerScenarios":"Passing a null Action to Throws<TException>, commonly from a conditionally assigned delegate variable or a helper that builds the action lazily and returns null on some path.","commonSituations":"Test parameterization where one row forgot to supply the action; refactors that replaced a lambda with a nullable method reference; dynamic test-case generation producing null delegates.","solutions":["Pass a real delegate: () => codeThatShouldThrow();","Fix the helper/fixture that produced the null action.","Guard with a null check or xUnit's Assert.Throws in tests where actions are data-driven."],"exampleFix":"// before\nAction act = BuildAction(case); // may be null\nReactiveAssert.Throws<InvalidOperationException>(act);\n// after\nAction act = BuildAction(case) ?? throw new ArgumentException(\"missing action for case\");\nReactiveAssert.Throws<InvalidOperationException>(act);","handlingStrategy":"validation","validationCode":"if (action == null)\n    throw new InvalidOperationException(\"Action must be provided for Throws assertion\");\nReactiveAssert.Throws<InvalidOperationException>(action);","typeGuard":"if (action is not { } validAction) throw new ArgumentException(\"action is null\");","tryCatchPattern":"try\n{\n    ReactiveAssert.Throws<ArgumentException>(action);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"action\")\n{\n    Assert.Fail(\"Test data missing the action delegate\");\n}","preventionTips":["Always pass inline lambdas: () => sut.Call().","Avoid nullable Action fields in test fixtures.","Validate data-driven test rows before asserting.","Prefer Assert.Throws from the test framework when actions are dynamic."],"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"}