{"record":{"id":"0739b8ea949cf047","repo":"OrchardCMS/OrchardCore","slug":"the-calendar-is-not-supported","errorCode":null,"errorMessage":"The calendar is not supported.","messagePattern":"The calendar is not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore/Localization/BclCalendars.cs","lineNumber":26,"sourceCode":"    public static readonly Calendar Hebrew = new HebrewCalendar();\n    public static readonly Calendar Hijri = new HijriCalendar();\n    public static readonly Calendar Gregorian = new GregorianCalendar();\n    public static readonly Calendar Julian = new JulianCalendar();\n    public static readonly Calendar Persian = new PersianCalendar();\n    public static readonly Calendar UmAlQura = new UmAlQuraCalendar();\n\n    public static CalendarSystem GetCalendarByName(CalendarName calendarName) =>\n        calendarName switch\n        {\n            CalendarName.Hebrew => CalendarSystem.HebrewCivil,\n            CalendarName.Hijri => CalendarSystem.IslamicBcl,\n            CalendarName.Gregorian => CalendarSystem.Iso,\n            CalendarName.Julian => CalendarSystem.Julian,\n            CalendarName.Persian => CultureInfo.CurrentUICulture.Calendar.IsLeapYear(1)\n            ? CalendarSystem.PersianSimple\n            : CalendarSystem.PersianAstronomical,\n            CalendarName.UmAlQura => CalendarSystem.UmAlQura,\n            _ => throw new NotSupportedException($\"The calendar is not supported.\"),\n        };\n\n    public static CalendarName GetCalendarName(Calendar calendar)\n    {\n        ArgumentNullException.ThrowIfNull(calendar);\n\n        var calendarType = calendar.GetType();\n        if (calendarType == typeof(GregorianCalendar))\n        {\n            return CalendarName.Gregorian;\n        }\n        else if (calendarType == typeof(HebrewCalendar))\n        {\n            return CalendarName.Hebrew;\n        }\n        else if (calendarType == typeof(HijriCalendar))\n        {\n            return CalendarName.Hijri;","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore/Localization/BclCalendars.cs#L8-L44","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar calendar = BclCalendars.GetCalendarByName((CalendarName)7); // throws\n\n// after\nvar name = Enum.IsDefined(typeof(CalendarName), 7) && name is CalendarName.Gregorian or CalendarName.Julian or CalendarName.Persian or CalendarName.UmAlQura\n    ? (CalendarName)7 : CalendarName.Gregorian;\nvar calendar = BclCalendars.GetCalendarByName(name);","handlingStrategy":"fallback","validationCode":"static readonly CalendarName[] Supported = [CalendarName.Gregorian, CalendarName.Julian, CalendarName.Persian, CalendarName.UmAlQura];\nbool isSupported = Enum.IsDefined(typeof(CalendarName), value) && Supported.Contains(value);","typeGuard":"bool IsSupportedCalendar(CalendarName name) =>\n    name is CalendarName.Gregorian or CalendarName.Julian or CalendarName.Persian or CalendarName.UmAlQura;","tryCatchPattern":"try { calendar = BclCalendars.GetCalendarByName(name); }\ncatch (NotSupportedException) { calendar = CalendarSystem.Iso; /* fallback to Gregorian */ }","preventionTips":["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."],"tags":["localization","calendar","enum"],"backgroundTag":"unsupported-enum-value","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}