{"record":{"id":"d52967393bc081b2","repo":"HangfireIO/Hangfire","slug":"context","errorCode":null,"errorMessage":"context","messagePattern":"context","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/CaptureCultureAttribute.cs","lineNumber":76,"sourceCode":"\n        [CanBeNull]\n        public string DefaultUICultureName { get; }\n\n        public bool CaptureDefault { get; }\n\n#if !NETSTANDARD1_3\n        /// <summary>\n        /// Gets or sets whether to use the <see cref=\"GetCultureInfo\"/> method when getting\n        /// a culture by its name, or create a <see cref=\"CultureInfo\"/> instance using its\n        /// constructor instead. Cached method does not respect user-overridden values associated\n        /// with the current culture specified on the OS level.\n        /// </summary>\n        public bool CachedCulture { get; set; }\n#endif\n\n        public void OnCreating(CreatingContext context)\n        {\n            if (context == null) throw new ArgumentNullException(nameof(context));\n\n            var currentCulture = CultureInfo.CurrentCulture;\n            var currentUICulture = CultureInfo.CurrentUICulture;\n\n            if (CaptureDefault == false && currentCulture.Name.Equals(DefaultCultureName, StringComparison.Ordinal))\n            {\n                // Don't set the 'CurrentCulture' job parameter when it's equal to the default one\n            }\n            else\n            {\n                context.SetJobParameter(\"CurrentCulture\", currentCulture.Name);\n            }\n\n            if (CaptureDefault == false && currentUICulture.Name.Equals(DefaultUICultureName, StringComparison.Ordinal))\n            {\n                // Don't set the 'CurrentUICulture' job parameter when it's equal to the default one\n            }\n            else if (GlobalConfiguration.HasCompatibilityLevel(CompatibilityLevel.Version_180) &&","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/CaptureCultureAttribute.cs#L58-L94","documentation":"Thrown by CaptureCultureAttribute.OnCreating when the CreatingContext argument is null. This is a standard null-guard (ArgumentNullException) protecting the IClientFilter.OnCreating pipeline that captures the current thread's CurrentCulture and CurrentUICulture into job parameters before enqueueing. Hangfire internally invokes OnCreating during job creation via its filter pipeline, so a null context indicates a programming error in a custom filter provider or test harness, not a runtime/infrastructure issue.","triggerScenarios":"Calling new CaptureCultureAttribute().OnCreating(null) directly, or a custom IClientFilter provider that manually dispatches the attribute's OnCreating with a null context. Also reproducible in unit tests that instantiate the attribute and invoke the filter method without constructing a real CreatingContext.","commonSituations":"Writing unit tests for a custom job filter that wraps CaptureCultureAttribute; integrating a custom IBackgroundJobClient or IJobFilterProvider that constructs filter invocation pipelines manually; reflection-based invocation that passes null due to a missing context object.","solutions":["Ensure OnCreating is never called directly by application code — rely on Hangfire's filter pipeline (BackgroundJob.Create -> BackgroundJobFactory.Create -> filter dispatch) which always supplies a non-null context.","If invoking the filter manually (e.g., in a test), construct a valid CreatingContext from a CreateContext with a real or mock IStorageConnection, Job, and initial state.","Add a null check in your own caller before dispatching to OnCreating and fail with a descriptive error upstream."],"exampleFix":"// before (broken test/manual call)\nvar attr = new CaptureCultureAttribute();\nattr.OnCreating(null);\n\n// after — construct a real context\nvar createContext = new CreateContext(storage, connection, job, initialState);\nvar creatingContext = new CreatingContext(createContext);\nattr.OnCreating(creatingContext);","handlingStrategy":"validation","validationCode":"if (context == null) throw new ArgumentException(\"CreatingContext is required before invoking CaptureCultureAttribute.OnCreating\", nameof(context));\n// or guard in your dispatch code\nif (creatingContext == null) return;\nattr.OnCreating(creatingContext);","typeGuard":"public static bool IsValidCreatingContext(CreatingContext ctx)\n    => ctx != null && ctx.Job != null && ctx.Items != null;","tryCatchPattern":null,"preventionTips":["Never call IClientFilter.OnCreating manually — let Hangfire's BackgroundJobFactory pipeline invoke it.","In tests, always build a CreatingContext from a CreateContext with a real or mocked storage and connection.","If you implement a custom filter provider, validate the context before dispatching to each filter."],"tags":["argument-null","culture","job-filter","client-filter"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}