{"record":{"id":"d36fe60acaf4ca87","repo":"HangfireIO/Hangfire","slug":"options","errorCode":null,"errorMessage":"options","messagePattern":"options","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/BackgroundJobServer.cs","lineNumber":101,"sourceCode":"            : this(options, storage, additionalProcesses, null, null, null, null, null)\n#pragma warning restore 618\n        {\n        }\n\n        [Obsolete(\"Create your own BackgroundJobServer-like type and pass custom services to it. This constructor will be removed in 2.0.0.\")]\n        [EditorBrowsable(EditorBrowsableState.Advanced)]\n        public BackgroundJobServer(\n            [NotNull] BackgroundJobServerOptions options,\n            [NotNull] JobStorage storage,\n            [NotNull] IEnumerable<IBackgroundProcess> additionalProcesses,\n            [CanBeNull] IJobFilterProvider filterProvider,\n            [CanBeNull] JobActivator activator,\n            [CanBeNull] IBackgroundJobFactory factory,\n            [CanBeNull] IBackgroundJobPerformer performer,\n            [CanBeNull] IBackgroundJobStateChanger stateChanger)\n        {\n            if (storage == null) throw new ArgumentNullException(nameof(storage));\n            if (options == null) throw new ArgumentNullException(nameof(options));\n            if (additionalProcesses == null) throw new ArgumentNullException(nameof(additionalProcesses));\n\n            _options = options;\n\n            var processes = new List<IBackgroundProcessDispatcherBuilder>();\n            processes.AddRange(GetRequiredProcesses(filterProvider, activator, factory, performer, stateChanger));\n            processes.AddRange(additionalProcesses.Select(static x => x.UseBackgroundPool(1)));\n\n            var properties = new Dictionary<string, object>\n            {\n                { \"Queues\", options.Queues },\n                { \"WorkerCount\", options.WorkerCount }\n            };\n\n            _logger.Info($\"Starting Hangfire Server using job storage: '{storage}'\");\n\n            storage.WriteOptionsToLog(_logger);\n","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/BackgroundJobServer.cs#L83-L119","documentation":"This ArgumentNullException(\"options\") is thrown by the detailed BackgroundJobServer constructor when the BackgroundJobServerOptions argument is null. BackgroundJobServer requires an options instance to configure WorkerCount, Queues, timeouts and intervals; passing null prevents the server from configuring its worker pool and processes. The throw fires before _options is assigned or any process is built.","triggerScenarios":"Calling the advanced constructor (or one of the two-argument overloads) with options set to null; e.g. new BackgroundJobServer(null, storage) or resolving BackgroundJobServerOptions as null from DI.","commonSituations":"DI container does not register BackgroundJobServerOptions (it is not registered automatically); manually constructing the server and forgetting `new BackgroundJobServerOptions()`; conditional construction where a config section binds to null; refactor that dropped the options argument.","solutions":["Pass a non-null BackgroundJobServerOptions (use `new BackgroundJobServerOptions()` for defaults).","Register BackgroundJobServerOptions in DI or bind it from IConfiguration.","Prefer the parameterless BackgroundJobServer() constructor which supplies default options.","Guard at the call site: `options ?? new BackgroundJobServerOptions()`."],"exampleFix":"// before\nvar server = new BackgroundJobServer(null, storage);\n\n// after\nvar server = new BackgroundJobServer(new BackgroundJobServerOptions { WorkerCount = 10 }, storage);","handlingStrategy":"validation","validationCode":"var options = new BackgroundJobServerOptions();\nvar server = new BackgroundJobServer(options, storage);","typeGuard":"static bool IsOptionsValid(BackgroundJobServerOptions options) => options is not null;","tryCatchPattern":"try { var server = new BackgroundJobServer(options, storage); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"options\") { throw new InvalidOperationException(\"BackgroundJobServerOptions was not provided.\", ex); }","preventionTips":["Register BackgroundJobServerOptions in DI or bind it from config.","Prefer the parameterless constructor when defaults suffice.","Coerce null to new BackgroundJobServerOptions()."],"tags":["csharp","hangfire","argumentnullexception","configuration","constructor","background-jobs"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}