Azure Functions error Not a valid cron expression or TimeSpan
The schedule expression '0 0 12 ? * MON' was not recognized as a valid cron expression or timespan string.
System.ArgumentException: The schedule expression '0 0 12 ? * MON' was not recognized as a valid cron expression or timespan string.Message text from TimerSchedule.cs in azure-webjobs-sdk-extensions. Which expressions fail follows the tester’s own engine.
What it means
The timer trigger tries the expression as NCRONTAB first, then as a TimeSpan such as 01:00:00. This message means both failed, and it doesn’t say why. The quoted expression is the one after app-setting names like %TimerSchedule% have been resolved, so check what the setting actually holds.
NCRONTAB is plainer than it looks. It takes six fields with seconds first, or five without seconds, and only numbers, names, *, ranges, lists and steps: no ?, L, W or #, and no year. Day of week runs from 0 (Sunday) to 6.
Rejected expressions and their fixes
Each expression opens in the tester. The message under a rejected one is built the way the source above builds it.
-
Rejected0 0 12 ? * MONThe schedule expression '0 0 12 ? * MON' was not recognized as a valid cron expression or timespan string.Use0 0 12 * * MONAt 12:00, on Mondays.
Quartz or EventBridge style. Azure has no
?; use*. -
Rejectedcron(0 12 * * ? *)The schedule expression 'cron(0 12 * * ? *)' was not recognized as a valid cron expression or timespan string.Use0 0 12 * * *At 12:00.
An EventBridge expression. Drop the wrapper and the year, and add seconds.
-
Rejected0 0 9 * * 7The schedule expression '0 0 9 * * 7' was not recognized as a valid cron expression or timespan string.Use0 0 9 * * 0At 09:00, on Sundays.
Sundays at 09:00. Sunday is 0; 7 is out of range.
-
Rejected0 0 9 * * MON#1The schedule expression '0 0 9 * * MON#1' was not recognized as a valid cron expression or timespan string.Use0 0 9 1-7 * MONAt 09:00, on the 1st through the 7th of the month, but only when that day is also Monday.
First Monday of the month. Azure requires both day fields to match, so “a Monday that falls on the 1st to the 7th” is exactly the first Monday.
-
Rejected0 0 0 L * *The schedule expression '0 0 0 L * *' was not recognized as a valid cron expression or timespan string.InsteadNo single Azure expressionTested workaround
Last day of the month. Run on days 28 to 31 and return early unless tomorrow is the 1st.
Questions
- Does Azure Functions accept five-field cron?
- Yes. With exactly five fields it reads them without seconds; with any other count the first field is seconds. Microsoft’s docs show six.
- Why does
0 0 9 1-7 * MONmean the first Monday in Azure but not in cron? - Azure requires both day fields to match. Unix cron and Kubernetes run when either one matches, so there it means the 1st to the 7th plus every Monday.