{"record":{"id":"0be03723edaf417d","repo":"HangfireIO/Hangfire","slug":"wrong-number-of-parts-in-the-cronexpression-cr","errorCode":null,"errorMessage":"Wrong number of parts in the `{cronExpression}` cron expression, you can only use 5 or 6 (with seconds) part-based expressions.","messagePattern":"Wrong number of parts in the `(.+?)` cron expression, you can only use 5 or 6 \\(with seconds\\) part-based expressions\\.","errorType":"exception","errorClass":"CronFormatException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/RecurringJobEntity.cs","lineNumber":300,"sourceCode":"            return String.Join(\";\", _recurringJob.Select(static x => $\"{x.Key}:{x.Value}\"));\n        }\n\n        public static CronExpression ParseCronExpression([NotNull] string cronExpression)\n        {\n            if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression));\n\n            var format = CronFormat.Standard;\n\n            if (!cronExpression.StartsWith(\"@\", StringComparison.OrdinalIgnoreCase))\n            {\n                var parts = cronExpression.Split(SeparatorCharacters, StringSplitOptions.RemoveEmptyEntries);\n                if (parts.Length == 6)\n                {\n                    format |= CronFormat.IncludeSeconds;\n                }\n                else if (parts.Length != 5)\n                {\n                    throw new CronFormatException(\n                        $\"Wrong number of parts in the `{cronExpression}` cron expression, you can only use 5 or 6 (with seconds) part-based expressions.\");\n                }\n            }\n\n            return CronExpression.Parse(cronExpression, format);\n        }\n    }\n}","sourceCodeStart":282,"sourceCodeEnd":308,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/RecurringJobEntity.cs#L282-L308","documentation":"Thrown by RecurringJobEntity.ParseCronExpression when a cron expression that doesn't start with '@' does not split into exactly 5 or 6 (with seconds) whitespace-separated parts. Hangfire uses Cronos and requires standard 5-field or 6-field-with-seconds expressions. This is a CronFormatException surfaced before the expression is handed to Cronos.","triggerScenarios":"Passing a cron string with 4 fields (e.g. '* * * *'), 7 fields, empty string, or a malformed schedule. Happens during AddOrUpdate validation and during scheduling when the stored Cron is read.","commonSituations":"Quartz-style 7-field expressions mistakenly used. Extra/missing spaces or trailing tokens. Copying a cron from a system that uses a different field count. Empty or whitespace-only cron from a misconfigured setting.","solutions":["Use exactly 5 fields (min hour day month weekday) or 6 fields when seconds are needed.","Validate the cron string with a unit test or a cron validator before calling AddOrUpdate.","If you need named macros, use '@daily', '@hourly', etc., which bypass the part-count check."],"exampleFix":"// before\nRecurringJob.AddOrUpdate(\"j\", () => Work(), \"0 12 * *\"); // 4 fields\n\n// after\nRecurringJob.AddOrUpdate(\"j\", () => Work(), \"0 12 * * *\"); // 5 fields","handlingStrategy":"validation","validationCode":"static bool IsValidCronParts(string cron)\n{\n    if (string.IsNullOrEmpty(cron) || cron.StartsWith(\"@\")) return cron?.StartsWith(\"@\") == true;\n    var parts = cron.Split(new[] { ' ', '\\t' }, StringSplitOptions.RemoveEmptyEntries);\n    return parts.Length == 5 || parts.Length == 6;\n}","typeGuard":null,"tryCatchPattern":"try { RecurringJob.AddOrUpdate(id, () => Work(), cron); }\ncatch (CronFormatException ex) { /* fix cron string */ }","preventionTips":["Use 5-field cron by default; add a 6th only when seconds are required.","Validate cron strings with a unit test covering all scheduled jobs.","Prefer Cron.* helpers or @macros to avoid hand-crafted field counts."],"tags":["cron","recurring-job","validation"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}