dotnet/wpf · error · ArgumentOutOfRangeException
SR.Calendar_UnSelectableDates
Error message
SR.Calendar_UnSelectableDates
What it means
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).
Solutions
- Validate the range against DisplayDateStart/DisplayDateEnd before adding
- Check CalendarBlackoutDatesCollection.IsValid(range) before inserting
- Clamp the range to the calendar's display range
Example fix
// before
calendar.BlackoutDates.Add(new CalendarDateRange(minDate, maxDate));
// after
var range = new CalendarDateRange(minDate, maxDate);
if (calendar.BlackoutDates.IsValid(range))
calendar.BlackoutDates.Add(range); Defensive patterns
Strategy: validation
Validate before calling
bool ok = range.Start >= calendar.DisplayDateStart && range.End <= calendar.DisplayDateEnd
&& calendar.BlackoutDates.IsValid(range);
if (ok) calendar.BlackoutDates.Add(range);
Type guard
bool IsBlackoutable(Calendar c, CalendarDateRange r) => c.BlackoutDates.IsValid(r);
Try / catch
try
{
calendar.BlackoutDates.Add(range);
}
catch (ArgumentOutOfRangeException)
{
// clamp range to display bounds or skip
}
Prevention
- Call IsValid before inserting a range
- Clamp ranges to DisplayDateStart/DisplayDateEnd
- Sanitize external date data before blacking out
When it happens
Trigger: 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).
Common situations: Blackout dates computed from external data exceeding DisplayDateStart/DisplayDateEnd; blacking out today's date or all days; typos in hardcoded year ranges.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.Calendar_OnSelectedDateChanged_InvalidValue
- args
- args
- ArgumentOutOfRangeException(authenticationType)
- ArgumentOutOfRangeException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/be10ac440aeed6b7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/CalendarBlackoutDatesCollection.cs:190
/// </summary>
/// <param name="index"></param>
/// <param name="item"></param>
protected override void InsertItem(int index, CalendarDateRange item)
{
if (!IsValidThread())
{
throw new NotSupportedException(SR.CalendarCollection_MultiThreadedCollectionChangeNotSupported);
}
if (IsValid(item))
{
RegisterItem(item);
base.InsertItem(index, item);
_owner.UpdateCellItems();
}
else
{
throw new ArgumentOutOfRangeException(SR.Calendar_UnSelectableDates);
}
}
/// <summary>
/// The item in the specified index is removed from the collection.
/// </summary>
/// <param name="index"></param>
protected override void RemoveItem(int index)
{
if (!IsValidThread())
{
throw new NotSupportedException(SR.CalendarCollection_MultiThreadedCollectionChangeNotSupported);
}
if (index >= 0 && index < this.Count)
{
UnRegisterItem(Items[index]);
}View on GitHub (pinned to 81131a70a4)