{"record":{"id":"2434394562cfd770","repo":"dotnet/reactive","slug":"nameof-subscribe","errorCode":null,"errorMessage":"nameof(subscribe)","messagePattern":"nameof\\(subscribe\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Creation.cs","lineNumber":31,"sourceCode":"        #region + Create +\n\n        /// <summary>\n        /// Creates an observable sequence from a specified Subscribe method implementation.\n        /// </summary>\n        /// <typeparam name=\"TResult\">The type of the elements in the produced sequence.</typeparam>\n        /// <param name=\"subscribe\">Implementation of the resulting observable sequence's Subscribe method.</param>\n        /// <returns>The observable sequence with the specified implementation for the Subscribe method.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"subscribe\"/> is null.</exception>\n        /// <remarks>\n        /// Use of this operator is preferred over manual implementation of the <see cref=\"IObservable{T}\"/> interface. In case\n        /// you need a type implementing <see cref=\"IObservable{T}\"/> rather than an anonymous implementation, consider using\n        /// the <see cref=\"ObservableBase{T}\"/> abstract base class.\n        /// </remarks>\n        public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, IDisposable> subscribe)\n        {\n            if (subscribe == null)\n            {\n                throw new ArgumentNullException(nameof(subscribe));\n            }\n\n            return s_impl.Create(subscribe);\n        }\n\n        /// <summary>\n        /// Creates an observable sequence from a specified Subscribe method implementation.\n        /// </summary>\n        /// <typeparam name=\"TResult\">The type of the elements in the produced sequence.</typeparam>\n        /// <param name=\"subscribe\">Implementation of the resulting observable sequence's Subscribe method, returning an Action delegate that will be wrapped in an IDisposable.</param>\n        /// <returns>The observable sequence with the specified implementation for the Subscribe method.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"subscribe\"/> is null.</exception>\n        /// <remarks>\n        /// Use of this operator is preferred over manual implementation of the <see cref=\"IObservable{T}\"/> interface. In case\n        /// you need a type implementing <see cref=\"IObservable{T}\"/> rather than an anonymous implementation, consider using\n        /// the <see cref=\"ObservableBase{T}\"/> abstract base class.\n        /// </remarks>\n        public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, Action> subscribe)","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Creation.cs#L13-L49","documentation":"Observable.Create<TResult> with a Func<IObserver<TResult>, IDisposable> throws ArgumentNullException when the subscribe delegate is null. Create is the canonical way to build custom observables, and Rx validates the delegate before constructing the observable. The null check ensures the failure occurs at Create, not at subscription time.","triggerScenarios":"Calling Observable.Create<TResult>(subscribe) with a null Func<IObserver<TResult>, IDisposable>, e.g. a delegate variable not assigned or a factory returning null.","commonSituations":"Conditional delegate assignment patterns, refactoring that removed the subscription lambda, or reflection/late-bound delegate resolution failing.","solutions":["Supply a valid subscribe lambda: o => { ...; return Disposable.Empty; }","Fix the factory/variable that resolved to null","Guard with a null check before Create"],"exampleFix":"// before\nvar obs = Observable.Create<int>(subscribe); // subscribe is null\n// after\nvar obs = Observable.Create<int>(o =>\n{\n    o.OnNext(1);\n    o.OnCompleted();\n    return Disposable.Empty;\n});","handlingStrategy":"validation","validationCode":"if (subscribe == null) throw new ArgumentNullException(nameof(subscribe));\nvar obs = Observable.Create<T>(subscribe);","typeGuard":"bool IsValid<T>(Func<IObserver<T>, IDisposable> f) => f is not null;","tryCatchPattern":"try { var obs = Observable.Create<T>(subscribe); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"subscribe\") { /* handle null delegate */ }","preventionTips":["Always pass an inline lambda to Observable.Create","Avoid nullable delegate variables; assign at declaration","Return Disposable.Empty for no-op teardown instead of leaving nulls"],"tags":["dotnet","rx","null-argument","delegate"],"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"}