{"record":{"id":"7b3205e2db5abeac","repo":"abpframework/abp","slug":"job-args-types-cannot-contain-null","errorCode":null,"errorMessage":"Job args types cannot contain null.","messagePattern":"Job args types cannot contain null\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AbpBackgroundJobWorkerOptions.cs","lineNumber":199,"sourceCode":"    }\n\n    public AbpBackgroundJobWorkerOptions AddDedicatedWorker<TArgs1, TArgs2>()\n    {\n        return AddDedicatedWorker(typeof(TArgs1), typeof(TArgs2));\n    }\n\n    public AbpBackgroundJobWorkerOptions AddDedicatedWorker<TArgs1, TArgs2, TArgs3>()\n    {\n        return AddDedicatedWorker(typeof(TArgs1), typeof(TArgs2), typeof(TArgs3));\n    }\n\n    protected virtual string GetDedicatedWorkerLockName(Type[] jobArgsTypes)\n    {\n        Check.NotNullOrEmpty(jobArgsTypes, nameof(jobArgsTypes));\n\n        if (jobArgsTypes.Any(t => t == null))\n        {\n            throw new ArgumentException(\"Job args types cannot contain null.\", nameof(jobArgsTypes));\n        }\n\n        // Hash the (stable, sorted) full type names so the derived lock name stays short and within the\n        // length limits of distributed lock providers (e.g. SQL Server sp_getapplock is limited to 255 chars).\n        var key = string.Join(\",\", jobArgsTypes.Select(t => t.FullName).Distinct().OrderBy(n => n, StringComparer.Ordinal));\n        return \"AbpBackgroundJobDedicatedWorker:\" + key.ToMd5();\n    }\n}\n","sourceCodeStart":181,"sourceCodeEnd":208,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AbpBackgroundJobWorkerOptions.cs#L181-L208","documentation":"Thrown by AbpBackgroundJobWorkerOptions.GetDedicatedWorkerLockName via Check.NotNullOrEmpty plus an explicit null-element scan: the jobArgsTypes array must be non-empty AND contain no null elements, otherwise it throws ArgumentException. This guards the hashing step (which reads t.FullName) from a NullReferenceException.","triggerScenarios":"Calling AddDedicatedWorker with a Type[] that contains a null entry (e.g. typeof(SomeGeneric<>).MakeGenericType(...) returning null, or an array built with an unset slot).","commonSituations":"Building the Type[] dynamically where a reflection call yields null; generic type construction failure silently producing null; a default(Type) placeholder left in the array; passing new Type[] { null } by mistake.","solutions":["Filter nulls out of the Type[] before calling AddDedicatedWorker.","Fix the reflection/generic-type code that produced the null Type.","Validate the array with a debug assert or a guard clause at the call site.","Use the strongly-typed generic overloads (AddDedicatedWorker<TArgs>) to avoid runtime nulls."],"exampleFix":"// before\nvar types = new[] { typeof(EmailJobArgs), maybeNullType };\noptions.AddDedicatedWorker(types); // throws 'cannot contain null'\n// after\nvar types = new[] { typeof(EmailJobArgs), maybeNullType }\n    .Where(t => t != null).ToArray();\noptions.AddDedicatedWorker(types);","handlingStrategy":"type-guard","validationCode":"var clean = jobArgsTypes.Where(t => t != null).ToArray();\nif (clean.Length != jobArgsTypes.Length) { /* fix the producer of nulls */ }\noptions.AddDedicatedWorker(clean);","typeGuard":"static bool HasNoNulls(Type[] types) => types != null && types.Length > 0 && types.All(t => t is not null);","tryCatchPattern":"try { options.AddDedicatedWorker(types); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"cannot contain null\"))\n{ /* filter nulls / fix reflection that produced them */ }","preventionTips":["Prefer the generic AddDedicatedWorker<TArgs> overloads to avoid runtime nulls.","Validate reflection results before adding to the array.","Add a debug assert that no slot is null.","Build Type[] arrays from known concrete types."],"tags":["background-jobs","abp","validation","reflection","null"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}