dotnet/wpf · error · ArgumentException

SR.InvalidParameter

Error message

SR.InvalidParameter

What it means

WindowsListView's IMultipleViewProvider.GetViewName throws ArgumentException(SR.InvalidParameter) when the viewID is negative or greater than ListViewViews.Length. View IDs index into the fixed table of supported list-view views, so only IDs within that table are valid.

Solutions

  1. Enumerate MultipleViewPattern.GetSupportedViews() and use only those ids with GetViewName.
  2. Validate 0 <= viewID < supported count before calling.
  3. Catch ArgumentException and return/skip unknown view ids.
  4. Do not use ListViewViews.Length itself as an id (valid ids are 0..Length).

Example fix

// before
string name = mv.GetViewName(9); // guessed id
// after
foreach (int id in mv.GetSupportedViews()) Console.WriteLine(mv.GetViewName(id));
Defensive patterns

Strategy: validation

Validate before calling

int[] supported = ((MultipleViewPattern)element.GetCurrentPattern(MultipleViewPattern.Pattern)).GetSupportedViews();
if (Array.IndexOf(supported, viewID) >= 0) { mv.GetViewName(viewID); }

Try / catch

try { name = mv.GetViewName(viewID); } catch (ArgumentException) { /* unsupported view id */ }

Prevention

When it happens

Trigger: Calling GetViewName(viewID) with viewID < 0 or viewID > ListViewViews.Length — e.g. passing an arbitrary/foreign view id instead of one obtained from GetSupportedViews.

Common situations: Scripts hard-coding view ids instead of enumerating supported views; view ids from a different control type; off-by-one when treating Length as a valid index.

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


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListView.cs:825

        RowOrColumnMajor ITableProvider.RowOrColumnMajor
        {
            get
            {
                return RowOrColumnMajor.RowMajor;
            }
        }


        #endregion Table Pattern

        #region MultipleViewPattern

        // In the future use the official table for different views
        string IMultipleViewProvider.GetViewName (int viewID)
        {
            if ( viewID < 0 || viewID > ListViewViews.Length )
            {
                throw new ArgumentException(SR.InvalidParameter);
            }
            return ListViewViews [viewID];
        }

        void IMultipleViewProvider.SetCurrentView (int viewID)
        {
            if ( viewID < 0 || viewID > ListViewViews.Length )
            {
                throw new ArgumentException(SR.InvalidParameter);
            }
            // App specific: App will provide us with the SupportedViews array
            // How this would be done is TBD

            // If requested view is in array, than do a Set
            // {
            //     return ListViewSetView(_hwnd, viewID);
            // }

View on GitHub (pinned to 81131a70a4)