abpframework/abp · error · ArgumentException

Job args types cannot contain null.

Error message

Job args types cannot contain null.

What it means

Thrown by the BackgroundJobWorkerConfiguration constructor when one of the elements in the jobArgsTypes array is null. The configuration rejects null elements because a dedicated worker must be bound to concrete job argument types to filter and claim jobs. This is an ArgumentException raised at configuration time, before any worker starts.

Source

Thrown at framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorkerConfiguration.cs:32

    /// It is used to serialize the worker across application instances when
    /// <see cref="AbpBackgroundJobWorkerOptions.MaxParallelJobExecutionCount"/> is 1; in parallel mode
    /// (greater than 1) jobs are claimed with per-job locks instead and this lock is not acquired.
    /// </summary>
    public string LockName { get; }

    /// <summary>
    /// The job argument types that are processed exclusively by this worker.
    /// </summary>
    public IReadOnlyList<Type> JobArgsTypes { get; }

    public BackgroundJobWorkerConfiguration(string lockName, params Type[] jobArgsTypes)
    {
        LockName = Check.NotNullOrWhiteSpace(lockName, nameof(lockName));
        Check.NotNullOrEmpty(jobArgsTypes, nameof(jobArgsTypes));

        if (jobArgsTypes.Any(t => t == null))
        {
            throw new ArgumentException("Job args types cannot contain null.", nameof(jobArgsTypes));
        }

        JobArgsTypes = jobArgsTypes.ToList();
    }
}

View on GitHub (pinned to 7ed43b1931)

Solutions

  1. Filter the Type[] array for nulls before calling AddDedicatedWorker: jobArgsTypes.Where(t => t != null).ToArray().
  2. Use the strongly-typed generic overloads (AddDedicatedWorker<TArgs>, AddDedicatedWorker<TArgs1, TArgs2>) which cannot introduce null elements.
  3. Debug the source of the null entry (e.g. log Type.GetType(name) results) and fix the lookup so it never returns null for expected job types.

Example fix

// before
var types = names.Select(Type.GetType).ToArray();
options.AddDedicatedWorker("lock", types);

// after
var types = names
    .Select(Type.GetType)
    .Where(t => t != null)
    .ToArray();
if (types.Length != names.Count) throw new InvalidOperationException("One or more job types could not be resolved.");
options.AddDedicatedWorker("lock", types);
Defensive patterns

Strategy: validation

Validate before calling

Type[] jobArgsTypes = ResolveTypes();
if (jobArgsTypes.Any(t => t == null))
{
    throw new InvalidOperationException("jobArgsTypes contains a null entry; resolve before calling AddDedicatedWorker.");
}
options.AddDedicatedWorker(lockName, jobArgsTypes);

Type guard

static bool HasNoNulls(Type[] types) => types != null && types.All(t => t != null);

Prevention

When it happens

Trigger: Calling the non-generic AddDedicatedWorker(string lockName, params Type[] jobArgsTypes) overload on AbpBackgroundJobWorkerOptions and passing a Type[] array that contains at least one null element (e.g. new Type[] { typeof(MyJobArgs), null }). The generic overloads (AddDedicatedWorker<TArgs>) cannot produce this because typeof(TArgs) is never null.

Common situations: Building a Type[] dynamically from a collection of types where one entry resolved to null (e.g. a Type.GetType(string) call that returned null for an unrecognized name). Reflecting job types from an assembly where a type-load failure silently yields null. Copying a list that was not filtered for nulls before passing it to AddDedicatedWorker.

Related errors


AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13). Data as JSON: /api/errors/b5e829767e4dba77. Report an issue: GitHub.