{"record":{"id":"e7e67f31a4bf5713","repo":"dotnet/reactive","slug":"argumentnullexception-default-message-value-cannot-be-null-e7e67f","errorCode":null,"errorMessage":"ArgumentNullException (default message: Value cannot be null. (Parameter 'values'))","messagePattern":"ArgumentNullException \\(default message: Value cannot be null\\. \\(Parameter 'values'\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Single.cs","lineNumber":797,"sourceCode":"\n        /// <summary>\n        /// Prepends a sequence of values to an observable sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to prepend values to.</param>\n        /// <param name=\"values\">Values to prepend to the specified sequence.</param>\n        /// <returns>The source sequence prepended with the specified values.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"values\"/> is null.</exception>\n        public static IObservable<TSource> StartWith<TSource>(this IObservable<TSource> source, params TSource[] values)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (values == null)\n            {\n                throw new ArgumentNullException(nameof(values));\n            }\n\n            return s_impl.StartWith(source, values);\n        }\n\n        /// <summary>\n        /// Prepends a sequence of values to an observable sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to prepend values to.</param>\n        /// <param name=\"values\">Values to prepend to the specified sequence.</param>\n        /// <returns>The source sequence prepended with the specified values.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"values\"/> is null.</exception>\n        public static IObservable<TSource> StartWith<TSource>(this IObservable<TSource> source, IEnumerable<TSource> values)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));","sourceCodeStart":779,"sourceCodeEnd":815,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Single.cs#L779-L815","documentation":"StartWith prepends the given values to the source; the values array is validated because the pre-emission queue cannot be built from null. Fix: pass an empty array (or use StartWithEmpty-style behavior) instead of null.","triggerScenarios":"Calling StartWith(source, values) with a null params array, e.g. passing a null TSource[] variable or forwarding a null from another params call.","commonSituations":"Forwarding optional prelude values through helper methods where null means 'no prefix' instead of an empty array; config-driven value lists that failed to load.","solutions":["Pass an empty array instead of null (`Array.Empty<TSource>()`).","Normalize null to empty at the helper boundary before forwarding.","Fix the loader that produced a null values list.","Use the StartWith(IEnumerable<TSource>) overload with an empty collection."],"exampleFix":"// before\npublic IObservable<int> Build(IObservable<int> src, int[] prefix) => src.StartWith(prefix);\n// after\npublic IObservable<int> Build(IObservable<int> src, int[]? prefix) => src.StartWith(prefix ?? Array.Empty<int>());","handlingStrategy":"validation","validationCode":"if (values is null) throw new ArgumentNullException(nameof(values));\nvar withPrefix = source.StartWith(values);","typeGuard":"bool HasValues<TSource>(TSource[]? v) => v is not null;","tryCatchPattern":"try { withPrefix = source.StartWith(vals); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"values\") { withPrefix = source; }","preventionTips":["Use Array.Empty<T>() instead of null for 'no elements'.","Normalize params forwarding at API boundaries: `prefix ?? Array.Empty<T>()`.","Avoid passing optional collections as null; use empty collections by convention."],"tags":["rx","null-check","params-array"],"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"}