{"record":{"id":"f5e90d41c1523cc2","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-f5e90d","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/Publish.cs","lineNumber":38,"sourceCode":"        /// at the point of obtaining the enumerator.\n        /// </returns>\n        /// <example>\n        /// var rng = Enumerable.Range(0, 10).Publish();\n        /// var e1 = rng.GetEnumerator();    // e1 has a view on the source starting from element 0\n        /// Assert.IsTrue(e1.MoveNext());\n        /// Assert.AreEqual(0, e1.Current);\n        /// Assert.IsTrue(e1.MoveNext());\n        /// Assert.AreEqual(1, e1.Current);\n        /// var e2 = rng.GetEnumerator();\n        /// Assert.IsTrue(e2.MoveNext());    // e2 has a view on the source starting from element 2\n        /// Assert.AreEqual(2, e2.Current);\n        /// Assert.IsTrue(e1.MoveNext());    // e1 continues to enumerate over its view\n        /// Assert.AreEqual(2, e1.Current);\n        /// </example>\n        public static IBuffer<TSource> Publish<TSource>(this IEnumerable<TSource> source)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            return new PublishedBuffer<TSource>(source.GetEnumerator());\n        }\n\n        /// <summary>\n        /// Publishes the source sequence within a selector function where each enumerator can obtain a view over a tail of the\n        /// source sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <typeparam name=\"TResult\">Result sequence element type.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"selector\">Selector function with published access to the source sequence for each enumerator.</param>\n        /// <returns>Sequence resulting from applying the selector function to the published view over the source sequence.</returns>\n        public static IEnumerable<TResult> Publish<TSource, TResult>(this IEnumerable<TSource> source, Func<IEnumerable<TSource>, IEnumerable<TResult>> selector)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (selector == null)","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/Publish.cs#L20-L56","documentation":"Publish(source) throws ArgumentNullException when the source sequence is null. Publish buffers the sequence for multicasting, and it needs a real enumerator, so the argument is validated eagerly before creating the PublishedBuffer.","triggerScenarios":"Calling source.Publish() where source is a null IEnumerable<TSource>.","commonSituations":"Passing a nullable sequence obtained from parsing, deserialization, or an optional collection property straight into Publish.","solutions":["Ensure the source is non-null before publishing; substitute Enumerable.Empty<TSource>().","Coalesce at the call: (source ?? Enumerable.Empty<T>()).Publish().","Fix the code path that produced a null sequence."],"exampleFix":"// before\nvar buffer = source.Publish(); // source may be null\n// after\nvar buffer = (source ?? Enumerable.Empty<int>()).Publish();","handlingStrategy":"validation","validationCode":"if (source == null) source = Enumerable.Empty<int>();\nvar buffer = source.Publish();","typeGuard":"static bool CanPublish(IEnumerable<int>? source) => source is not null;","tryCatchPattern":"try\n{\n    using var buffer = source.Publish();\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\")\n{\n    // handle missing source\n}","preventionTips":["Null-coalesce optional sequences before entering multicasting pipelines.","Keep nullability explicit with nullable annotations on APIs feeding Publish.","Publish only sequences with verified ownership/lifetime."],"tags":["null-reference","argument-validation","linq"],"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"}