{"record":{"id":"001a11aaf805970b","repo":"HangfireIO/Hangfire","slug":"cron-expression-is-invalid-please-see-the-inner-e","errorCode":null,"errorMessage":"CRON expression is invalid. Please see the inner exception for details.","messagePattern":"CRON expression is invalid\\. Please see the inner exception for details\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/RecurringJobManager.cs","lineNumber":162,"sourceCode":"                {\n                    using (var transaction = connection.CreateWriteTransaction())\n                    {\n                        transaction.UpdateRecurringJob(recurringJob, changedFields, _logger);\n                        transaction.Commit();\n                    }\n                }\n            }\n        }\n \n        private static void ValidateCronExpression(string cronExpression)\n        {\n            try\n            {\n                RecurringJobEntity.ParseCronExpression(cronExpression);\n            }\n            catch (Exception ex) when (ex.IsCatchableExceptionType())\n            {\n                throw new ArgumentException(\n                    \"CRON expression is invalid. Please see the inner exception for details.\",\n                    nameof(cronExpression),\n                    ex);\n            }\n        }\n\n        public void Trigger(string recurringJobId) => TriggerJob(recurringJobId);\n\n        [Obsolete(\"Please use the `TriggerJob` method instead. Will be removed in 2.0.0.\")]\n        public string TriggerExecution(string recurringJobId) => TriggerJob(recurringJobId);\n\n        public string TriggerJob(string recurringJobId)\n        {\n            if (recurringJobId == null) throw new ArgumentNullException(nameof(recurringJobId));\n\n            using (var connection = _storage.GetConnection())\n            using (connection.AcquireDistributedRecurringJobLock(recurringJobId, DefaultTimeout))\n            {","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/RecurringJobManager.cs#L144-L180","documentation":"Thrown by RecurringJobManager.ValidateCronExpression as an ArgumentException wrapping any exception (CronFormatException, parse errors) from RecurringJobEntity.ParseCronExpression. It is the user-facing error for an unparseable cron string supplied to AddOrUpdate, preserving the original cause as InnerException.","triggerScenarios":"Calling recurringJobManager.AddOrUpdate(id, job, cronExpression, options) or RecurringJob.AddOrUpdate(id, methodCall, badCron, ...) where badCron fails parsing (wrong field count, invalid ranges, bad macro).","commonSituations":"Typo in a cron literal, using a 6-or-7-field expression on a path expecting 5, invalid characters, or a macro the Cronos parser rejects. Config-supplied cron that is malformed.","solutions":["Inspect InnerException for the precise parse failure (often a CronFormatException with the offending field).","Correct the cron string to a valid 5- or 6-field expression or a supported @macro.","Validate cron at config-load time using RecurringJobEntity.ParseCronExpression or a cron library so startup fails fast with a clear message."],"exampleFix":"// before\nRecurringJob.AddOrUpdate(\"j\", () => Work(), \"0 25 * * *\"); // hour out of range\n\n// after\nRecurringJob.AddOrUpdate(\"j\", () => Work(), \"0 23 * * *\");","handlingStrategy":"validation","validationCode":"static void ValidateCron(string cron)\n{\n    try { Hangfire.RecurringJobEntity.ParseCronExpression(cron); }\n    catch (Exception ex) when (ex.IsCatchableExceptionType())\n    { throw new ArgumentException($\"Invalid cron: {cron}\", ex); }\n}","typeGuard":null,"tryCatchPattern":"try { RecurringJob.AddOrUpdate(id, () => Work(), cron); }\ncatch (ArgumentException ex) when (ex.ParamName == \"cronExpression\")\n{ /* inspect ex.InnerException for details */ }","preventionTips":["Validate cron at config load so startup fails fast.","Always inspect InnerException for the precise parse error.","Run a cron-linter or unit test over all configured cron expressions."],"tags":["cron","recurring-job","validation","argument"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}