{"record":{"id":"e454e2d8544e45b1","repo":"HangfireIO/Hangfire","slug":"client","errorCode":null,"errorMessage":"client","messagePattern":"client","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/BackgroundJobClientExtensions.cs","lineNumber":485,"sourceCode":"        }\n\n        /// <summary>\n        /// Creates a new background job based on a specified lambda expression and schedules\n        /// it to be enqueued to the specified queue at the specified moment.\n        /// </summary>\n        /// <typeparam name=\"T\">Type whose method will be invoked during job processing.</typeparam>\n        /// <param name=\"client\">A job client instance.</param>\n        /// <param name=\"queue\">Default queue for the background job.</param>\n        /// <param name=\"methodCall\">Method call expression that will be marshalled to the Server.</param>\n        /// <param name=\"enqueueAt\">Moment at which the job will be enqueued.</param>\n        /// <returns>Unique identifier of a created job.</returns>\n        public static string Schedule<T>(\n            [NotNull] this IBackgroundJobClient client,\n            [NotNull] string queue,\n            [NotNull, InstantHandle] Expression<Func<T, Task>> methodCall,\n            DateTimeOffset enqueueAt)\n        {\n            if (client == null) throw new ArgumentNullException(nameof(client));\n            return client.Create(queue, methodCall, new ScheduledState(enqueueAt.UtcDateTime));\n        }\n\n        /// <summary>\n        /// Creates a new background job based on a specified lambda expression in a given state.\n        /// </summary>\n        /// <param name=\"client\">A job client instance.</param>\n        /// <param name=\"methodCall\">Static method call expression that will be marshalled to the Server.</param>\n        /// <param name=\"state\">Initial state of a job.</param>\n        /// <returns>Unique identifier of the created job.</returns>\n        public static string Create(\n            [NotNull] this IBackgroundJobClient client,\n            [NotNull, InstantHandle] Expression<Action> methodCall,\n            [NotNull] IState state)\n        {\n            if (client == null) throw new ArgumentNullException(nameof(client));\n\n            return client.Create(Job.FromExpression(methodCall), state);","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/BackgroundJobClientExtensions.cs#L467-L503","documentation":"The Schedule<T> extension (with an explicit queue) is a null-check guard: it throws ArgumentNullException with paramName 'client' when the IBackgroundJobClient argument is null. The message field shows just 'client' because that is the parameter name. The method then delegates to client.Create with a ScheduledState. This is the standard extension-method null guard — extension methods run on a null 'this' and do not use instance dispatch.","triggerScenarios":"Calling client.Schedule<T>(queue, expr, enqueueAt) where 'client' resolved to null — e.g., DI did not register IBackgroundJobClient, the static JobStorage.Current is unconfigured (so BackgroundJob.Client is null), or a field/property was never initialized.","commonSituations":"Forgot to call services.AddHangfire(...)/AddHangfireServer in ASP.NET Core DI; using new BackgroundJobClient() before GlobalConfiguration.UseXXXStorage; accessing the client in a context without DI scope; calling the static BackgroundJob.Schedule before JobStorage is configured.","solutions":["Ensure IBackgroundJobClient is registered — call GlobalConfiguration.Configuration.UseXXXStorage() before using the static BackgroundJob API, or inject IBackgroundJobClient via DI.","Verify JobStorage.Current is non-null before using static helpers.","If constructing manually, pass a valid JobStorage to new BackgroundJobClient(storage).","Null-check the client before calling the extension if its source is uncertain."],"exampleFix":"// before\nIBackgroundJobClient client = null;\nclient.Schedule<MyService>(\"queue\", x => x.DoAsync(), at); // throws\n\n// after\nvar client = new BackgroundJobClient(JobStorage.Current);\nclient.Schedule<MyService>(\"queue\", x => x.DoAsync(), at);","handlingStrategy":"validation","validationCode":"if (client == null) throw new InvalidOperationException(\"IBackgroundJobClient not configured\");\nclient.Schedule<T>(queue, expr, enqueueAt);","typeGuard":"static bool IsClientReady(IBackgroundJobClient client) => client != null && JobStorage.Current != null;","tryCatchPattern":null,"preventionTips":["Call GlobalConfiguration.Configuration.UseXXXStorage() before any static Schedule.","Inject IBackgroundJobClient via DI rather than holding nullable state.","Assert JobStorage.Current is non-null at startup."],"tags":["di","configuration","argumentnullexception","extension-method","schedule"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}