{"record":{"id":"9171ade6c976c521","repo":"HangfireIO/Hangfire","slug":"configuration-9171ad","errorCode":null,"errorMessage":"configuration","messagePattern":"configuration","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/GlobalConfigurationExtensions.cs","lineNumber":38,"sourceCode":"using Hangfire.Annotations;\nusing Hangfire.Common;\nusing Hangfire.Dashboard;\nusing Hangfire.Dashboard.Pages;\nusing Hangfire.Logging;\nusing Hangfire.Logging.LogProviders;\nusing Newtonsoft.Json;\n\nnamespace Hangfire\n{\n    [EditorBrowsable(EditorBrowsableState.Never)]\n    public static class GlobalConfigurationExtensions\n    {\n        public static IGlobalConfiguration<TStorage> UseStorage<TStorage>(\n            [NotNull] this IGlobalConfiguration configuration,\n            [NotNull] TStorage storage)\n            where TStorage : JobStorage\n        {\n            if (configuration == null) throw new ArgumentNullException(nameof(configuration));\n            if (storage == null) throw new ArgumentNullException(nameof(storage));\n\n            return configuration.Use(storage, static x => JobStorage.Current = x);\n        }\n\n        public static IGlobalConfiguration<TStorage> WithJobExpirationTimeout<TStorage>(\n            [NotNull] this IGlobalConfiguration<TStorage> configuration,\n            TimeSpan timeout)\n            where TStorage : JobStorage\n        {\n            if (configuration == null) throw new ArgumentNullException(nameof(configuration));\n\n            configuration.Entry.JobExpirationTimeout = timeout;\n            return configuration;\n        }\n\n        public static IGlobalConfiguration<TActivator> UseActivator<TActivator>(\n            [NotNull] this IGlobalConfiguration configuration,","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/GlobalConfigurationExtensions.cs#L20-L56","documentation":"UseStorage registers a JobStorage and assigns JobStorage.Current. It throws ArgumentNullException(nameof(configuration)) at GlobalConfigurationExtensions.cs:38 when the receiver is null — the method needs the configuration both to register the storage and to return it for further chaining.","triggerScenarios":"Calling .UseStorage(storage) on a null IGlobalConfiguration, e.g. ((IGlobalConfiguration)null).UseStorage(sqlStorage), or on a field whose DI assignment returned null.","commonSituations":"Forgetting to begin the chain from GlobalConfiguration.Configuration; a custom hosting extension that accepts IGlobalConfiguration but receives null; calling UseStorage before GlobalConfiguration is initialized.","solutions":["Begin from GlobalConfiguration.Configuration (never-null singleton).","Null-check any IGlobalConfiguration variable before chaining.","Ensure the DI/factory providing the config never returns null.","Compose the config chain in a single expression so no intermediate can be null."],"exampleFix":"// before\nIGlobalConfiguration cfg = GetConfigOrNull();\ncfg.UseStorage(new SqlServerStorage(cns));\n// after\nGlobalConfiguration.Configuration.UseStorage(new SqlServerStorage(cns));","handlingStrategy":"validation","validationCode":"GlobalConfiguration.Configuration.UseStorage(storage);\n\n// or guard a captured variable:\nif (configuration == null)\n    throw new ArgumentNullException(nameof(configuration));\nif (storage == null)\n    throw new ArgumentNullException(nameof(storage));\nconfiguration.UseStorage(storage);","typeGuard":"static bool IsReady(IGlobalConfiguration? c, JobStorage? s) => c != null && s != null;","tryCatchPattern":null,"preventionTips":["Always chain off GlobalConfiguration.Configuration.","Null-check both configuration and storage before UseStorage.","Configure storage once, early in startup, before any worker starts.","Enable nullable reference types."],"tags":["csharp","hangfire","argument-null","configuration","storage"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}