{"record":{"id":"8bf080e9b0f4f753","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-startswith","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'source')","messagePattern":"Value cannot be null\\. \\(Parameter 'source'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive/System/Linq/Operators/StartsWith.cs","lineNumber":21,"sourceCode":"// See the LICENSE file in the project root for more information. \n\nusing System.Collections.Generic;\n\nnamespace System.Linq\n{\n    public static partial class EnumerableEx\n    {\n        /// <summary>\n        /// Returns the source sequence prefixed with the specified value.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"values\">Values to prefix the sequence with.</param>\n        /// <returns>Sequence starting with the specified prefix value, followed by the source sequence.</returns>\n        public static IEnumerable<TSource> StartWith<TSource>(this IEnumerable<TSource> source, params TSource[] values)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            return StartWithCore(source, values);\n        }\n\n        private static IEnumerable<TSource> StartWithCore<TSource>(IEnumerable<TSource> source, params TSource[] values)\n        {\n            foreach (var x in values)\n            {\n                yield return x;\n            }\n\n            foreach (var item in source)\n            {\n                yield return item;\n            }\n        }\n    }\n}","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/StartsWith.cs#L3-L39","documentation":"StartWith is an extension method that prefixes a sequence with the given values. The library eagerly validates its `source` parameter at call time and throws ArgumentNullException naming `source` when a caller passes null. All argument validation happens when the operator is invoked, not when the result is enumerated.","triggerScenarios":"Calling `null.StartWith(1, 2)` or `StartWith(someNullableCollection, 1)` where the IEnumerable<TSource> argument is null; e.g. chaining off a method that can return null or an uninitialized field.","commonSituations":"Chaining off a nullable LINQ result (FirstOrDefault-style helpers or API calls that return null for 'no data'), uninitialized backing fields, or deserialized objects with null collection properties passed straight into the operator.","solutions":["Ensure the sequence passed to StartWith is non-null before calling (use `?? Array.Empty<TSource>()`).","Check the upstream call that produced the source; make it return an empty sequence instead of null.","If null legitimately means 'no data', skip the operator and return a default sequence.","Wrap in ArgumentNullException-handling only at API boundaries; otherwise fix the null at the source."],"exampleFix":"// before\nvar result = maybeNullItems.StartWith(0);\n// after\nvar result = (maybeNullItems ?? Array.Empty<int>()).StartWith(0);","handlingStrategy":"validation","validationCode":"if (source is null) throw new ArgumentNullException(nameof(source));\n// or coalesce: var src = source ?? Array.Empty<TSource>();","typeGuard":"static bool IsNonNullSeq<T>(IEnumerable<T> s) => s is not null;","tryCatchPattern":"try { var r = input.StartWith(0); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* handle null source */ }","preventionTips":["Enable nullable reference types (NRT) so null sources are flagged at compile time.","Coalesce optional sequences at ingestion points.","Avoid methods that return null sequences; return empty collections.","Validate inputs at API boundaries before building LINQ pipelines."],"tags":["linq","null-argument","ix-interactive"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}