HangfireIO/Hangfire · error · ArgumentNullException

type

Error message

type

What it means

Thrown as ArgumentNullException by the obsolete Job(Type, MethodInfo, string[]) constructor when the 'type' argument is null. The constructor records the owning Type, MethodInfo, and pre-serialized arguments for a background job; a null type makes the job unidentifiable and is rejected at line 31.

Source

Thrown at src/Hangfire.Core/Obsolete/Job.Obsolete.cs:31

// You should have received a copy of the GNU Lesser General Public 
// License along with Hangfire. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Reflection;
using Hangfire.Annotations;
using Hangfire.Server;
using Hangfire.Storage;

// ReSharper disable once CheckNamespace
namespace Hangfire.Common
{
    partial class Job
    {
        [Obsolete("Please use Job(Type, MethodInfo, object[]) ctor overload instead. Will be removed in 2.0.0.")]
        public Job([NotNull] Type type, [NotNull] MethodInfo method, [NotNull] string[] arguments)
        {
            if (type == null) throw new ArgumentNullException(nameof(type));
            if (method == null) throw new ArgumentNullException(nameof(method));
            if (arguments == null) throw new ArgumentNullException(nameof(arguments));

            Validate(type, nameof(type), method, nameof(method), arguments.Length, nameof(arguments));

            Type = type;
            Method = method;
            Args = InvocationData.DeserializeArguments(method, arguments);
        }

        /// <exclude />
        [NotNull]
        [Obsolete("Please use `Args` property instead to avoid unnecessary serializations/deserializations. Will be deleted in 2.0.0.")]
        public string[] Arguments => InvocationData.SerializeArguments(Method, Args);

        /// <exclude />
        [Obsolete("This method is deprecated. Please use `CoreBackgroundJobPerformer` or `BackgroundJobPerformer` classes instead. Will be removed in 2.0.0.")]
        public object Perform(JobActivator activator, IJobCancellationToken cancellationToken)

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Use the non-obsolete Job(Type, MethodInfo, object[]) constructor overload instead of this string-arguments variant.
  2. Null-check the Type before constructing the Job and log a clear error about which type failed to resolve.
  3. Ensure the type is resolvable: load the assembly first, or use typeof()/an expression-based Job.FromExpression call that resolves the type at compile time.

Example fix

// before
var type = Type.GetType("MyApp.Jobs, MyApp"); // returns null if assembly not loaded
var job = new Job(type, method, arguments);

// after
var job = Job.FromExpression<MyJobs>(x => x.DoWork(arg));
Defensive patterns

Strategy: validation

Validate before calling

if (type == null) throw new ArgumentNullException(nameof(type));
var job = new Job(type, method, arguments);

Type guard

static bool IsResolvableType(string fullName) => Type.GetType(fullName) != null;

Prevention

When it happens

Trigger: Calling 'new Job(null, method, arguments)' — i.e. constructing a Job with a null Type reference, often because the Type was resolved dynamically (e.g. Type.GetType returning null for an unqualified type name) and not null-checked before use.

Common situations: Reflective job construction where Type.GetType("Namespace.Type, Assembly") returns null due to a missing assembly load or a typo in the fully-qualified name; serialization round-trips that reconstruct the Job from stored data with a null type field; test helpers that pass null placeholders.

Related errors


AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13). Data as JSON: /api/errors/ab8f6579bf5c416c. Report an issue: GitHub.