OrchardCMS/OrchardCore · error · NotSupportedException
The calendar is not supported.
Error message
The calendar is not supported.
What it means
BclCalendars.GetCalendarByName maps a CalendarName enum value to an Noda Time CalendarSystem. Only Gregorian, Julian, Persian, and UmAlQura are mapped; any other value (or an out-of-range cast) hits the default arm, which throws NotSupportedException.
Solutions
- Use a supported calendar: Gregorian, Julian, Persian, or UmAlQura.
- Validate/normalize the calendar setting before calling (Enum.IsDefined plus an allow-list check).
- If a new CalendarName member was introduced, extend the switch expression to map it to a CalendarSystem.
- Catch NotSupportedException at the boundary and fall back to the ISO/Gregorian calendar.
Example fix
// before
var calendar = BclCalendars.GetCalendarByName((CalendarName)7); // throws
// after
var name = Enum.IsDefined(typeof(CalendarName), 7) && name is CalendarName.Gregorian or CalendarName.Julian or CalendarName.Persian or CalendarName.UmAlQura
? (CalendarName)7 : CalendarName.Gregorian;
var calendar = BclCalendars.GetCalendarByName(name); Defensive patterns
Strategy: fallback
Validate before calling
static readonly CalendarName[] Supported = [CalendarName.Gregorian, CalendarName.Julian, CalendarName.Persian, CalendarName.UmAlQura]; bool isSupported = Enum.IsDefined(typeof(CalendarName), value) && Supported.Contains(value);
Type guard
bool IsSupportedCalendar(CalendarName name) =>
name is CalendarName.Gregorian or CalendarName.Julian or CalendarName.Persian or CalendarName.UmAlQura; Try / catch
try { calendar = BclCalendars.GetCalendarByName(name); }
catch (NotSupportedException) { calendar = CalendarSystem.Iso; /* fallback to Gregorian */ } Prevention
- Validate calendar settings against the supported list when saving site/tenant options.
- Sanitize enum values parsed from strings or integers with Enum.IsDefined/Enum.TryParse.
- When adding a CalendarName member, update BclCalendars.GetCalendarByName in the same change.
- Default unknown calendars to Gregorian instead of passing them through.
When it happens
Trigger: Calling GetCalendarByName with a CalendarName value other than Gregorian, Julian, Persian, or UmAlQura — e.g., a cast integer, a config string bound into the enum, or a newly added enum member the switch doesn't cover.
Common situations: Site or tenant settings store an unsupported calendar value (e.g., Hebrew/Hijri requested by content but not mapped); upgrading code where a new CalendarName member was added without updating the switch; invalid enum parsing from user input.
Related errors
- Unexpected merge array handling when merging JSON.
- Unsupported Azure AI Search vector algorithm kind.
- Plural form ' ' doesn't exist for the key ' ' in the ' '…
- MessageId can't be empty.
- PluralForms array can't be empty, it must contain at least…
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/0739b8ea949cf047.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore/Localization/BclCalendars.cs:26
public static readonly Calendar Hebrew = new HebrewCalendar();
public static readonly Calendar Hijri = new HijriCalendar();
public static readonly Calendar Gregorian = new GregorianCalendar();
public static readonly Calendar Julian = new JulianCalendar();
public static readonly Calendar Persian = new PersianCalendar();
public static readonly Calendar UmAlQura = new UmAlQuraCalendar();
public static CalendarSystem GetCalendarByName(CalendarName calendarName) =>
calendarName switch
{
CalendarName.Hebrew => CalendarSystem.HebrewCivil,
CalendarName.Hijri => CalendarSystem.IslamicBcl,
CalendarName.Gregorian => CalendarSystem.Iso,
CalendarName.Julian => CalendarSystem.Julian,
CalendarName.Persian => CultureInfo.CurrentUICulture.Calendar.IsLeapYear(1)
? CalendarSystem.PersianSimple
: CalendarSystem.PersianAstronomical,
CalendarName.UmAlQura => CalendarSystem.UmAlQura,
_ => throw new NotSupportedException($"The calendar is not supported."),
};
public static CalendarName GetCalendarName(Calendar calendar)
{
ArgumentNullException.ThrowIfNull(calendar);
var calendarType = calendar.GetType();
if (calendarType == typeof(GregorianCalendar))
{
return CalendarName.Gregorian;
}
else if (calendarType == typeof(HebrewCalendar))
{
return CalendarName.Hebrew;
}
else if (calendarType == typeof(HijriCalendar))
{
return CalendarName.Hijri;View on GitHub (pinned to 4306c0717f)