{"record":{"id":"7fb32b2227794cfd","repo":"dotnet/reactive","slug":"nameof-gate","errorCode":null,"errorMessage":"nameof(gate)","messagePattern":"nameof\\(gate\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Concurrency.cs","lineNumber":172,"sourceCode":"        /// <summary>\n        /// Synchronizes the observable sequence such that observer notifications cannot be delivered concurrently, using the specified gate object.\n        /// This overload is useful when writing n-ary query operators, in order to prevent concurrent callbacks from different sources by synchronizing on a common gate object.\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=\"gate\">Gate object to synchronize each observer call on.</param>\n        /// <returns>The source sequence whose outgoing calls to observers are synchronized on the given gate object.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"gate\"/> is null.</exception>\n        public static IObservable<TSource> Synchronize<TSource>(this IObservable<TSource> source, object gate)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (gate == null)\n            {\n                throw new ArgumentNullException(nameof(gate));\n            }\n\n            return s_impl.Synchronize(source, gate);\n        }\n\n        #endregion\n    }\n}\n","sourceCodeStart":154,"sourceCodeEnd":181,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Concurrency.cs#L154-L181","documentation":"Synchronize<TSource>(source, object gate) throws ArgumentNullException when the gate object is null. The gate is the lock object on which outgoing observer calls are synchronized; Rx requires a concrete object to lock on and rejects null up front.","triggerScenarios":"Calling source.Synchronize(gate) with gate == null — e.g. a lazily-initialized lock field that was never created, or a gate passed through from an optional constructor parameter.","commonSituations":"Typical when the owning class's lock object is initialized in an Init/Start method that was not called, or when a null was supplied via DI as an optional gate.","solutions":["Pass a non-null lock object, e.g. a private readonly object _gate = new object();","Initialize the gate in the field declaration or constructor rather than lazily.","If no gate is needed, use the parameterless Synchronize() overload, which synchronizes on its own gate."],"exampleFix":"// before\nprivate object _gate; // never assigned\nsrc.Synchronize(_gate); // ArgumentNullException\n// after\nprivate readonly object _gate = new object();\nsrc.Synchronize(_gate);","handlingStrategy":"validation","validationCode":"if (gate is null) throw new InvalidOperationException(\"Lock gate not initialized\");\nvar synced = source.Synchronize(gate);","typeGuard":"static bool HasGate(object? gate) => gate is not null;","tryCatchPattern":"try { var s = source.Synchronize(gate); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"gate\") { log.Error(\"Gate object was null\"); }","preventionTips":["Declare lock objects as private readonly object _gate = new object();","Initialize gate in the constructor, not in a lazily-called Init method.","Use the parameterless Synchronize() overload when no external gate is required."],"tags":["rx","argumentnull","null-check","lock-object"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}