{"record":{"id":"a4d1de3b8f8b25ba","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-materialize","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'source')","messagePattern":"Value cannot be null\\. \\(Parameter 'source'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Materialize.cs","lineNumber":12,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<Notification<TSource>> Materialize<TSource>(this IAsyncObservable<TSource> source)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            return Create<TSource, Notification<TSource>>(source, static (source, observer) => source.SubscribeSafeAsync(AsyncObserver.Materialize(observer)));\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static IAsyncObserver<TSource> Materialize<TSource>(IAsyncObserver<Notification<TSource>> observer)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            return Create<TSource>(\n                x => observer.OnNextAsync(Notification.CreateOnNext(x)),\n                async ex =>\n                {\n                    await observer.OnNextAsync(Notification.CreateOnError<TSource>(ex)).ConfigureAwait(false);\n                    await observer.OnCompletedAsync().ConfigureAwait(false);","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Materialize.cs#L1-L30","documentation":"Materialize converts an async observable into a sequence of Notification<TSource> values; it validates its source at Materialize.cs:12 before wiring the Subscription. A null source cannot be subscribed to, so ArgumentNullException is thrown eagerly at operator construction.","triggerScenarios":"Calling AsyncObservable.Materialize<TSource>(null) — null IAsyncObservable<TSource> passed to the operator at Materialize.cs:12.","commonSituations":"Tracing/logging wrappers that materialize a stream obtained from a resolver or registry which returned null; unit tests passing null to check error behavior.","solutions":["Ensure the observable passed to Materialize is non-null.","Substitute an empty observable when the source is legitimately absent: source ?? AsyncObservable.Empty<T>().","Check upstream factory/registry code that produced a null observable."],"exampleFix":"// before\nvar notifications = AsyncObservable.Materialize(maybeSource); // null\n// after\nvar notifications = AsyncObservable.Materialize(maybeSource ?? AsyncObservable.Empty<T>());","handlingStrategy":"validation","validationCode":"if (source is null) throw new InvalidOperationException(\"Materialize requires a non-null source\");\nvar notifications = source.Materialize();","typeGuard":"static bool CanMaterialize<T>(IAsyncObservable<T>? s) => s is not null;","tryCatchPattern":"try { var notifications = source.Materialize(); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { var notifications = Array.Empty<Notification<T>>(); }","preventionTips":["Resolve streams from registries with non-null guarantees or coalesce to AsyncObservable.Empty<T>().","Enable nullable reference types to catch null sources statically.","Wrap stream-lookup helpers so they never return null observables."],"tags":["csharp","argument-null","asyncrx","materialize"],"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"}