dotnet/wpf · error · ArgumentOutOfRangeException

args

Error message

args

What it means

The RowCache change-processing switch handles a fixed set of RowCacheChangeTypes; any unrecognized type falls into the default case, which throws ArgumentOutOfRangeException(nameof(args)). This signals an unknown or future change type reaching the cache's handler.

Solutions

  1. Check the RowCacheChangeType value being produced — ensure it is a valid, defined enum member
  2. Initialize change-type fields explicitly instead of relying on default(enum)
  3. Verify assembly versions match so enum values are consistent between producer and consumer
  4. Extend the switch to handle any new change types if using a modified build

Example fix

// before
var args = new RowCacheChangedEventArgs(changes);
// after
if (!Enum.IsDefined(typeof(RowCacheChangeType), changeType))
{
    throw new ArgumentOutOfRangeException(nameof(changeType));
}
var args = new RowCacheChangedEventArgs(changes);
Defensive patterns

Strategy: validation

Validate before calling

if (!Enum.IsDefined(typeof(RowCacheChangeType), changeType)) throw new ArgumentOutOfRangeException(nameof(changeType));

Type guard

bool IsValidChangeType(RowCacheChangeType t) => Enum.IsDefined(typeof(RowCacheChangeType), t);

Try / catch

try { cache.ProcessChange(args); } catch (ArgumentOutOfRangeException) { logUnknownChangeType(args); }

Prevention

When it happens

Trigger: Passing a RowCacheChangedEventArgs whose change type is not one of the values handled by the switch (e.g. an invalid enum value, a type added by a newer version, or a wrongly-constructed change) into the RowCache change handler.

Common situations: Custom code constructing RowCacheChangedEventArgs with an uninitialized/default or out-of-range change type enum; version mismatch where a new RowCacheChangeType flows into older handler logic; wiring the wrong event args into the handler.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/1f538a107ac0a55e. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/RowCache.cs:1276

                            }

                            //If because of the above trimming we have fewer pages left 
                            //in the document than the columns that were initially requested
                            //We'll need to recalc our layout from scratch.
                            //First we check to see if we have one or fewer rows left.
                            if (_rowCache.Count <= 1)
                            {
                                //If we have either no rows left or the remaining row has
                                //less than _layoutColumns pages on it, we need to recalc from the first page.
                                if (_rowCache.Count == 0 || _rowCache[0].PageCount < _layoutColumns)
                                {
                                    RecalcRows(0, _layoutColumns);
                                }
                            }
                            break;

                        default:
                            throw new ArgumentOutOfRangeException(nameof(args));
                    }
                }

                RowCacheChangedEventArgs newArgs = new RowCacheChangedEventArgs(changes);
                RowCacheChanged(this, newArgs);
            }
            else if (_isLayoutRequested)
            {
                //We've had a request to create a layout previously, but didn't have enough pages to do so before.
                //Try it now.
                RecalcRows(_layoutPivotPage, _layoutColumns);
            }
        }

        /// <summary>
        /// Handler for the OnPaginationCompleted event.  If we still have an unfulfilled
        /// layout request, we'll call RecalcRows to ensure that we get a layout (though possibly
        /// with fewer columns than requested.)

View on GitHub (pinned to 81131a70a4)