{"record":{"id":"9780ffd08d95f345","repo":"HangfireIO/Hangfire","slug":"configuration","errorCode":null,"errorMessage":"configuration","messagePattern":"configuration","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/GlobalConfiguration.cs","lineNumber":61,"sourceCode":"        }\n\n        internal static bool HasCompatibilityLevel(CompatibilityLevel level)\n        {\n            return CompatibilityLevel >= level;\n        }\n\n        internal GlobalConfiguration()\n        {\n        }\n    }\n\n    public static class CompatibilityLevelExtensions\n    {\n        public static IGlobalConfiguration SetDataCompatibilityLevel(\n            [NotNull] this IGlobalConfiguration configuration,\n            CompatibilityLevel compatibilityLevel)\n        {\n            if (configuration == null) throw new ArgumentNullException(nameof(configuration));\n\n#if !NETSTANDARD1_3\n            if (!Enum.IsDefined(typeof(CompatibilityLevel), compatibilityLevel))\n                throw new InvalidEnumArgumentException(nameof(compatibilityLevel), (int) compatibilityLevel,\n                    typeof(CompatibilityLevel));\n#endif\n\n            GlobalConfiguration.CompatibilityLevel = compatibilityLevel;\n\n            return configuration;\n        }\n    }\n}\n","sourceCodeStart":43,"sourceCodeEnd":75,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/GlobalConfiguration.cs#L43-L75","documentation":"SetDataCompatibilityLevel is a fluent extension on IGlobalConfiguration that stores the data-serialization compatibility level. It throws ArgumentNullException(nameof(configuration)) at GlobalConfiguration.cs:61 when the receiver is null, because it must return that same configuration to keep the fluent chain alive.","triggerScenarios":"Invoking ((IGlobalConfiguration)null).SetDataCompatibilityLevel(CompatibilityLevel.Version_170), or storing the config in a field that is later null and calling .SetDataCompatibilityLevel on it.","commonSituations":"Not bootstrapping configuration from the singleton GlobalConfiguration.Configuration; assigning the IGlobalConfiguration from a DI factory that can return null; calling UseXxx before the config object is created.","solutions":["Start the fluent chain from GlobalConfiguration.Configuration, which is a never-null singleton (GlobalConfiguration.cs:37).","If you hold the config in a field/parameter, null-check it before chaining.","When wiring through DI, ensure the factory always returns a non-null IGlobalConfiguration.","Build the whole configuration chain in one statement so no intermediate variable can be null."],"exampleFix":"// before\nIGlobalConfiguration cfg = null;\ncfg.SetDataCompatibilityLevel(CompatibilityLevel.Version_170);\n// after\nGlobalConfiguration.Configuration\n    .SetDataCompatibilityLevel(CompatibilityLevel.Version_170);","handlingStrategy":"validation","validationCode":"// always start from the never-null singleton\nGlobalConfiguration.Configuration\n    .SetDataCompatibilityLevel(CompatibilityLevel.Version_170);\n\n// or, with a captured variable:\nif (configuration == null)\n    throw new ArgumentNullException(nameof(configuration));\nconfiguration.SetDataCompatibilityLevel(CompatibilityLevel.Version_170);","typeGuard":"static bool IsConfigured(IGlobalConfiguration? c) => c != null;","tryCatchPattern":null,"preventionTips":["Boot all Hangfire configuration from GlobalConfiguration.Configuration.","Never accept an IGlobalConfiguration from DI that can be null.","Set the compatibility level exactly once at startup.","Enable nullable reference types."],"tags":["csharp","hangfire","argument-null","configuration","compatibility"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}