{"record":{"id":"e501c7d241c0bec5","repo":"dotnet/reactive","slug":"begin","errorCode":null,"errorMessage":"begin","messagePattern":"begin","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Async.cs","lineNumber":84,"sourceCode":"        }\n\n        /// <summary>\n        /// Converts a Begin/End invoke function pair into an asynchronous function.\n        /// </summary>\n        /// <typeparam name=\"TArg1\">The type of the first argument passed to the begin delegate.</typeparam>\n        /// <typeparam name=\"TArg2\">The type of the second argument passed to the begin delegate.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the result returned by the end delegate.</typeparam>\n        /// <param name=\"begin\">The delegate that begins the asynchronous operation.</param>\n        /// <param name=\"end\">The delegate that ends the asynchronous operation.</param>\n        /// <returns>Function that can be used to start the asynchronous operation and retrieve the result as an observable sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"begin\"/> or <paramref name=\"end\"/> is null.</exception>\n        /// <remarks>Each invocation of the resulting function will cause the asynchronous operation to be started. Subscription to the resulting sequence has no observable side-effect, and each subscription will produce the asynchronous operation's result.</remarks>\n        [Obsolete(Constants_Linq.UseTaskFromAsyncPattern)]\n        public static Func<TArg1, TArg2, IObservable<TResult>> FromAsyncPattern<TArg1, TArg2, TResult>(Func<TArg1, TArg2, AsyncCallback, object?, IAsyncResult> begin, Func<IAsyncResult, TResult> end)\n        {\n            if (begin == null)\n            {\n                throw new ArgumentNullException(nameof(begin));\n            }\n\n            if (end == null)\n            {\n                throw new ArgumentNullException(nameof(end));\n            }\n\n            return s_impl.FromAsyncPattern(begin, end);\n        }\n\n        /// <summary>\n        /// Converts a Begin/End invoke function pair into an asynchronous function.\n        /// </summary>\n        /// <typeparam name=\"TArg1\">The type of the first argument passed to the begin delegate.</typeparam>\n        /// <typeparam name=\"TArg2\">The type of the second argument passed to the begin delegate.</typeparam>\n        /// <typeparam name=\"TArg3\">The type of the third argument passed to the begin delegate.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the result returned by the end delegate.</typeparam>\n        /// <param name=\"begin\">The delegate that begins the asynchronous operation.</param>","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Async.cs#L66-L102","documentation":"The two-argument FromAsyncPattern<TArg1,TArg2,TResult> overload throws ArgumentNullException('begin') when the Func<TArg1,TArg2,AsyncCallback,object?,IAsyncResult> begin delegate is null. The begin delegate starts the asynchronous operation for each invocation of the resulting function; it is required and checked eagerly. This APM-based overload family is also marked obsolete in favor of the Task-based API.","triggerScenarios":"Observable.FromAsyncPattern<TArg1,TArg2,TResult>(null, end) with two arguments and a valid end delegate.","commonSituations":"Reflection-based delegate construction failing silently; refactoring that removed a BeginXxx wrapper; passing a method group whose overload resolution failed and produced null in dynamic code.","solutions":["Provide a non-null begin delegate invoking the underlying BeginXxx method with both arguments","Assert delegate non-nullness before calling FromAsyncPattern","Replace with Observable.FromAsync((a,b) => Task-returning method)"],"exampleFix":"// before\nvar f = Observable.FromAsyncPattern<string, int, byte[]>(null, end);\n// after\nvar f = Observable.FromAsyncPattern<string, int, byte[]>(\n    (path, off, cb, st) => fs.BeginRead(buffer, off, size, cb, st),\n    iar => fs.EndRead(iar));","handlingStrategy":"validation","validationCode":"if (begin == null) throw new InvalidOperationException(\"begin delegate must be provided\");\nvar f = Observable.FromAsyncPattern<TArg1, TArg2, TResult>(begin, end);","typeGuard":"static bool HasBegin<TArg1,TArg2,TResult>(Func<TArg1, TArg2, AsyncCallback, object?, IAsyncResult> begin) => begin != null;","tryCatchPattern":"try\n{\n    var f = Observable.FromAsyncPattern<TArg1, TArg2, TResult>(begin, end);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"begin\")\n{\n    // repair the begin delegate\n}","preventionTips":["Reference BeginXxx method groups directly","Check dynamic delegate resolution results","Prefer Observable.FromAsync with async lambdas"],"tags":["csharp","null-argument","rx","async"],"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"}