{"record":{"id":"091b07592cccaee3","repo":"HangfireIO/Hangfire","slug":"context-091b07","errorCode":null,"errorMessage":"context","messagePattern":"context","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/JobParameterInjectionFilter.cs","lineNumber":30,"sourceCode":"// \n// You should have received a copy of the GNU Lesser General Public \n// License along with Hangfire. If not, see <http://www.gnu.org/licenses/>.\n\nusing System;\nusing System.Reflection;\nusing Hangfire.Common;\nusing Hangfire.Server;\nusing Hangfire.States;\n\nnamespace Hangfire\n{\n    public class JobParameterInjectionFilter : IServerFilter\n    {\n        internal static readonly string DefaultException = \"OCE\";\n\n        public void OnPerforming(PerformingContext context)\n        {\n            if (context == null) throw new ArgumentNullException(nameof(context));\n\n            var argumentsArray = context.BackgroundJob.Job?.Args as object[];\n            if (argumentsArray == null) return;\n\n            var parameters = context.BackgroundJob.Job.Method.GetParameters();\n\n            for (var index = 0; index < parameters.Length; index++)\n            {\n                var attribute = parameters[index].GetCustomAttribute<FromParameterAttribute>();\n                if (attribute == null) continue;\n\n                var parameterType = parameters[index].ParameterType;\n                var parameterName = attribute.ParameterName;\n\n                if (String.IsNullOrEmpty(parameterName)) continue;\n\n                var serialized = context.Connection.GetJobParameter(context.BackgroundJob.Id, parameterName);\n                if (serialized != null)","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/JobParameterInjectionFilter.cs#L12-L48","documentation":"Thrown by JobParameterInjectionFilter.OnPerforming when the PerformingContext parameter is null. This IServer filter injects job parameters (marked with [FromParameter]) into method arguments before execution; it requires a valid context to access BackgroundJob and its arguments.","triggerScenarios":"Calling OnPerforming(null) directly, or a custom server filter pipeline that passes null to this filter. In normal Hangfire operation, the framework always provides a non-null PerformingContext.","commonSituations":"Unit testing the filter without constructing a real PerformingContext, or a misconfigured server filter pipeline that drops the context. Extremely unlikely in production.","solutions":["In tests, construct a valid PerformingContext before calling OnPerforming","Ensure the filter is registered through the standard Hangfire pipeline (not invoked manually with null)","If calling the filter programmatically, guard against null context before invocation"],"exampleFix":"// before (in a test)\nfilter.OnPerforming(null);\n\n// after\nvar context = new PerformingContext(storage, connection, job, ...);\nfilter.OnPerforming(context);","handlingStrategy":"validation","validationCode":"if (context == null)\n    throw new InvalidOperationException(\"PerformingContext is required for OnPerforming.\");\nfilter.OnPerforming(context);","typeGuard":"context != null && context is PerformingContext","tryCatchPattern":null,"preventionTips":["Let the Hangfire framework invoke server filters; do not call OnPerforming manually with null","In unit tests, always construct a valid PerformingContext before invoking the filter","Register filters through IGlobalConfiguration.UseFilter rather than manual invocation"],"tags":["null-argument","server-filter","internal-api","hangfire"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}