{"record":{"id":"e65e1535fd8cece9","repo":"abpframework/abp","slug":"job-names-must-be-empty-when-the-filter-mode-is-no","errorCode":null,"errorMessage":"Job names must be empty when the filter mode is None.","messagePattern":"Job names must be empty when the filter mode is None\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobNameFilter.cs","lineNumber":34,"sourceCode":"    /// </summary>\n    public static BackgroundJobNameFilter None { get; } = new(BackgroundJobNameFilterMode.None);\n\n    public BackgroundJobNameFilterMode Mode { get; }\n\n    public IReadOnlyList<string> JobNames { get; }\n\n    public BackgroundJobNameFilter(BackgroundJobNameFilterMode mode, IReadOnlyList<string>? jobNames = null)\n    {\n        if (!Enum.IsDefined(typeof(BackgroundJobNameFilterMode), mode))\n        {\n            throw new ArgumentException($\"Invalid background job name filter mode: {mode}\", nameof(mode));\n        }\n\n        var names = jobNames?.Where(x => !x.IsNullOrWhiteSpace()).Distinct(StringComparer.Ordinal).ToList() ?? new List<string>();\n\n        if (mode == BackgroundJobNameFilterMode.None && names.Count > 0)\n        {\n            throw new ArgumentException(\"Job names must be empty when the filter mode is None.\", nameof(jobNames));\n        }\n\n        if (mode != BackgroundJobNameFilterMode.None && names.Count == 0)\n        {\n            throw new ArgumentException(\"Job names cannot be empty when the filter mode is Include or Exclude.\", nameof(jobNames));\n        }\n\n        Mode = mode;\n        JobNames = names.AsReadOnly();\n    }\n\n    public static BackgroundJobNameFilter Include(IReadOnlyList<string> jobNames)\n    {\n        return new BackgroundJobNameFilter(BackgroundJobNameFilterMode.Include, jobNames);\n    }\n\n    public static BackgroundJobNameFilter Exclude(IReadOnlyList<string> jobNames)\n    {","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobNameFilter.cs#L16-L52","documentation":"Thrown by the BackgroundJobNameFilter constructor when mode is None (match-everything) but a non-empty jobNames list (after filtering whitespace/null entries) was supplied. None semantically ignores names, so providing any is contradictory and treated as a programmer error.","triggerScenarios":"Constructing new BackgroundJobNameFilter(BackgroundJobNameFilterMode.None, new[] { \"job1\" }) - mode None but names non-empty.","commonSituations":"Reusing a filter-builder that always passes a name list even when the caller wants None; deserialization that populated names but set mode to None; copy-paste leaving a name list on a None filter.","solutions":["When using mode None, pass null or an empty list for jobNames.","Switch the mode to Include/Exclude if the names are actually meant to filter.","Use the static None property (BackgroundJobNameFilter.None) which is pre-built correctly.","Validate the (mode, names) pairing at the call site."],"exampleFix":"// before\nvar f = new BackgroundJobNameFilter(BackgroundJobNameFilterMode.None, names); // throws\n// after\nvar f = BackgroundJobNameFilter.None; // or new(..., None, null)","handlingStrategy":"validation","validationCode":"if (mode == BackgroundJobNameFilterMode.None && names?.Any(n => !n.IsNullOrWhiteSpace()) == true)\n{\n    /* clear names or switch mode before constructing */\n}","typeGuard":"null","tryCatchPattern":"try { var f = new BackgroundJobNameFilter(mode, names); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"must be empty when the filter mode is None\"))\n{ /* pass null/empty for None, or switch to Include/Exclude */ }","preventionTips":["Use BackgroundJobNameFilter.None instead of constructing a None filter manually.","Pass null for jobNames when mode is None.","Validate the (mode, names) pairing in builder code.","Unit-test filter construction for all valid mode/name combos."],"tags":["background-jobs","abp","validation","configuration"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}