{"record":{"id":"7a1a1c674a11127b","repo":"dotnet/reactive","slug":"nameof-context","errorCode":null,"errorMessage":"nameof(context)","messagePattern":"nameof\\(context\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Concurrency.cs","lineNumber":62,"sourceCode":"        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"context\">Synchronization context to notify observers on.</param>\n        /// <returns>The source sequence whose observations happen on the specified synchronization context.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"context\"/> is null.</exception>\n        /// <remarks>\n        /// This only invokes observer callbacks on a synchronization context. In case the subscription and/or unsubscription actions have side-effects\n        /// that require to be run on a synchronization context, use <see cref=\"Observable.SubscribeOn{TSource}(IObservable{TSource}, SynchronizationContext)\"/>.\n        /// </remarks>\n        public static IObservable<TSource> ObserveOn<TSource>(this IObservable<TSource> source, SynchronizationContext context)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (context == null)\n            {\n                throw new ArgumentNullException(nameof(context));\n            }\n\n            return s_impl.ObserveOn(source, context);\n        }\n\n        #endregion\n\n        #region + SubscribeOn +\n\n        /// <summary>\n        /// Wraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler. This operation is not commonly used;\n        /// see the remarks section for more information on the distinction between SubscribeOn and ObserveOn.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"scheduler\">Scheduler to perform subscription and unsubscription actions on.</param>\n        /// <returns>The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"scheduler\"/> is null.</exception>","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Concurrency.cs#L44-L80","documentation":"System.ArgumentNullException thrown by Observable.ObserveOn<TSource>(IObservable<TSource>, SynchronizationContext) when the context argument is null. The public wrapper validates both parameters before delegating to s_impl.ObserveOn, so a null SynchronizationContext is rejected immediately.","triggerScenarios":"Calling source.ObserveOn(context) with context == null, e.g. SynchronizationContext.Current captured before a UI context existed (or on a background thread where it is null).","commonSituations":"Capturing SynchronizationContext.Current in a console/background-thread app where it is null; caching the context in a static initialized too early; running the same code under unit tests without a UI context.","solutions":["Capture SynchronizationContext.Current only on the UI thread (e.g. in the Form/WPF constructor) before background work starts.","Fall back to a non-null context or switch to ObserveOn(dispatcher scheduler) when no context exists.","Use WindowsFormsSynchronizationContext.Current or the DispatcherScheduler explicitly instead of a null Current."],"exampleFix":"// before\nvar ctx = SynchronizationContext.Current; // null on background thread\nsource.ObserveOn(ctx);\n// after\nvar ctx = SynchronizationContext.Current ?? new SynchronizationContext();\nsource.ObserveOn(ctx);","handlingStrategy":"validation","validationCode":"var ctx = SynchronizationContext.Current ?? new SynchronizationContext();\nvar result = source.ObserveOn(ctx);","typeGuard":"bool HasSyncContext(SynchronizationContext c) => c is not null;","tryCatchPattern":"try { obs = source.ObserveOn(context); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"context\") { obs = source.ObserveOn(Scheduler.Default); }","preventionTips":["Capture SynchronizationContext.Current on the UI thread before starting background work.","Remember SynchronizationContext.Current is null on plain background threads and in most unit tests.","Prefer ObserveOn with a UI dispatcher scheduler (ObserveOnDispatcher/Control.ObserveOn) over raw context capture."],"tags":["null-argument","synchronization-context","rx","argumentnull"],"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"}