{"record":{"id":"be10ac440aeed6b7","repo":"dotnet/wpf","slug":"sr-calendar-unselectabledates","errorCode":null,"errorMessage":"SR.Calendar_UnSelectableDates","messagePattern":"SR\\.Calendar_UnSelectableDates","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/CalendarBlackoutDatesCollection.cs","lineNumber":190,"sourceCode":"        /// </summary>\n        /// <param name=\"index\"></param>\n        /// <param name=\"item\"></param>\n        protected override void InsertItem(int index, CalendarDateRange item)\n        {\n            if (!IsValidThread())\n            {\n                throw new NotSupportedException(SR.CalendarCollection_MultiThreadedCollectionChangeNotSupported);\n            }\n\n            if (IsValid(item))\n            {\n                RegisterItem(item);\n                base.InsertItem(index, item);\n                _owner.UpdateCellItems();\n            }\n            else\n            {\n                throw new ArgumentOutOfRangeException(SR.Calendar_UnSelectableDates);\n            }\n        }\n\n        /// <summary>\n        /// The item in the specified index is removed from the collection.\n        /// </summary>\n        /// <param name=\"index\"></param>\n        protected override void RemoveItem(int index)\n        {\n            if (!IsValidThread())\n            {\n                throw new NotSupportedException(SR.CalendarCollection_MultiThreadedCollectionChangeNotSupported);\n            }\n\n            if (index >= 0 && index < this.Count)\n            {\n                UnRegisterItem(Items[index]);\n            }","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/CalendarBlackoutDatesCollection.cs#L172-L208","documentation":"InsertItem throws ArgumentOutOfRangeException (with message SR.Calendar_UnSelectableDates) when the inserted CalendarDateRange is invalid for blackout purposes — the range fails IsValid, meaning it overlaps dates that must remain selectable (e.g. dates before DisplayDateStart or after DisplayDateEnd, or an invalid range).","triggerScenarios":"Adding a CalendarDateRange that lies outside the Calendar's valid display range or otherwise fails CalendarBlackoutDatesCollection.IsValid (e.g. blacking out the entire calendar such that no selectable dates remain).","commonSituations":"Blackout dates computed from external data exceeding DisplayDateStart/DisplayDateEnd; blacking out today's date or all days; typos in hardcoded year ranges.","solutions":["Validate the range against DisplayDateStart/DisplayDateEnd before adding","Check CalendarBlackoutDatesCollection.IsValid(range) before inserting","Clamp the range to the calendar's display range"],"exampleFix":"// before\ncalendar.BlackoutDates.Add(new CalendarDateRange(minDate, maxDate));\n// after\nvar range = new CalendarDateRange(minDate, maxDate);\nif (calendar.BlackoutDates.IsValid(range))\n    calendar.BlackoutDates.Add(range);","handlingStrategy":"validation","validationCode":"bool ok = range.Start >= calendar.DisplayDateStart && range.End <= calendar.DisplayDateEnd\n          && calendar.BlackoutDates.IsValid(range);\nif (ok) calendar.BlackoutDates.Add(range);\n","typeGuard":"bool IsBlackoutable(Calendar c, CalendarDateRange r) => c.BlackoutDates.IsValid(r);\n","tryCatchPattern":"try\n{\n    calendar.BlackoutDates.Add(range);\n}\ncatch (ArgumentOutOfRangeException)\n{\n    // clamp range to display bounds or skip\n}\n","preventionTips":["Call IsValid before inserting a range","Clamp ranges to DisplayDateStart/DisplayDateEnd","Sanitize external date data before blacking out"],"tags":["wpf","calendar","argument-out-of-range","blackout-dates"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}