{"record":{"id":"89ed6cf9efe4e999","repo":"HangfireIO/Hangfire","slug":"task","errorCode":null,"errorMessage":"task","messagePattern":"task","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Processing/TaskExtensions.cs","lineNumber":139,"sourceCode":"                {\n                    var asTask = type.GetRuntimeMethod(\"AsTask\", EmptyTypes);\n\n                    if (asTask != null && asTask.IsPublic && !asTask.IsStatic &&\n                        typeof(Task).GetTypeInfo().IsAssignableFrom(asTask.ReturnType.GetTypeInfo()))\n                    {\n                        getTaskFunc = obj => (Task) asTask.Invoke(obj, null);\n                        return true;\n                    }\n                }\n            }\n\n            getTaskFunc = null;\n            return false;\n        }\n\n        public static object GetTaskLikeResult([NotNull] this Task task, object obj, Type returnType)\n        {\n            if (task == null) throw new ArgumentNullException(nameof(task));\n\n            if (task != obj)\n            {\n                // We shouldn't call GetAwaiter/GetResult on ValueTask directly, because\n                // there may be a race condition as tells us this article:\n                // https://devblogs.microsoft.com/dotnet/understanding-the-whys-whats-and-whens-of-valuetask/#user-content-valid-consumption-patterns-for-valuetasks\n                // So we are waiting on task, returned by the AsTask method to ensure it's\n                // completed, before querying for the result.\n                task.GetAwaiter().GetResult();\n            }\n\n            // ReturnType is used instead of task.GetType, because we should return `null` result,\n            // when method is returning non-generic Task. However async state machines may use\n            // Task<VoidTaskResult> or Task<VoidResult> for these cases, and the number of such\n            // void types is pretty high. So it's much safer to call GetAwaiter/GetResult on an\n            // original result object.\n\n            // Awaitable type must have a public parameterless GetAwaiter instance method, ...","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Processing/TaskExtensions.cs#L121-L157","documentation":"Thrown by TaskExtensions.GetTaskLikeResult (internal) when the Task argument is null. The method calls task.GetAwaiter().GetResult() to ensure completion before extracting a result, so a null task would NRE.","triggerScenarios":"Calling task.GetTaskLikeResult(obj, returnType) where task is null. Reached when Hangfire's invocation pipeline resolves a job's return task to null (e.g., a job method returned null where a Task was expected).","commonSituations":"An async job method returns null instead of a Task (a coding error in the job); a ValueTask/Task conversion path yielded null; reflection invocation produced a null task object.","solutions":["Ensure async job methods return a Task (never null) — async methods always do; the issue is sync methods declaring Task return types and returning null.","Audit job methods that declare Task/Task<T> returns for `return null;` or missing return statements.","If wrapping invocation, coalesce null to Task.CompletedTask before this path."],"exampleFix":"// before\npublic Task RunAsync() { return null; } // job returning null Task\n\n// after\npublic Task RunAsync() { return DoWorkAsync(); }\n// or, for a no-op: public Task RunAsync() => Task.CompletedTask;","handlingStrategy":"validation","validationCode":"if (task == null) throw new ArgumentNullException(nameof(task));\nreturn task.GetTaskLikeResult(obj, returnType);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure async job methods always return a Task (never null).","Audit job methods declared as Task/Task<T> for `return null;`.","Coalesce null tasks to Task.CompletedTask when wrapping invocation."],"tags":["hangfire","null-argument","argument-validation","async","job-invocation"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}