dotnet/wpf · error · InvalidOperationException

SR.Format(SR.PathParameterIsNull, index)

Error message

SR.Format(SR.PathParameterIsNull, index)

What it means

ResolveIndexerParams throws this InvalidOperationException when an indexer parameter '(n)' in the path resolves to a valid index but PathParameters[n-1] is null. The parameter value is required to build the indexer arguments, and a null entry means the indexer argument cannot be produced.

Solutions

  1. Ensure every index referenced as '(n)' in the path has a non-null accessor in PathParameters[n-1]
  2. Remove the '(n)' reference from the path string if no parameter is intended
  3. Pre-validate the PathParameters collection for null entries before constructing/resolving the path
  4. Pass literal indexer values in the path string (e.g. '[3]') instead of parameter references

Example fix

// before
path.PathParameters.Add(null); // slot for '(1)'
// after
path.PathParameters.Add(typeof(C).GetProperty("Item")); // non-null accessor
Defensive patterns

Strategy: validation

Validate before calling

bool noNulls = path.PathParameters.Cast<object>().All(p => p != null);

Type guard

bool AllParamsNonNull(System.Collections.IEnumerable ps) => ps.Cast<object>().All(p => p != null);

Try / catch

try { path.ResolveIndexerParams(list, item, context, throwOnError: true); }
catch (InvalidOperationException ex) when (ex.Message.Contains("null")) { /* fill the missing parameter */ }

Prevention

When it happens

Trigger: Path string with '(1)' or '(2)' indexer references where the corresponding entry in the PathParameters collection was explicitly set to null; forgetting to initialize an accessor slot before constructing the PropertyPath.

Common situations: Building indexer paths like '[(0)]' for multi-binding indexers where one accessor slot is left null; conditional code paths that populate some but not all PathParameters entries; deserialization producing null accessor entries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs:726

                    // no value string "(2)" - value comes from PathParameter list
                    int index;
                    if (Int32.TryParse( paramList[i].parenString.Trim(),
                                        NumberStyles.Integer,
                                        TypeConverterHelper.InvariantEnglishUS.NumberFormat,
                                        out index))
                    {
                        if (0 <= index && index < PathParameters.Count)
                        {
                            object value = PathParameters[index];
                            if (value != null)
                            {
                                args[i].value = value;
                                args[i].type = value.GetType();
                            }
                            else if (throwOnError)
                            {
                                // info.value will still be "(n)"
                                throw new InvalidOperationException(SR.Format(SR.PathParameterIsNull, index));
                            }
                        }
                        else if (throwOnError)
                            throw new InvalidOperationException(SR.Format(SR.PathParametersIndexOutOfRange, index, PathParameters.Count));
                    }
                    else
                    {
                        // parens didn't hold an integer "(abc)" - value is (uninterpreted) paren string
                        // [this could be considered an error, but the original code
                        // treated it like this, so to preserve compatibility...]
                        args[i].value = $"({paramList[i].parenString})";
                    }
                }
                else
                {
                    // both strings appear "(Double)3.14159" - value is type-converted from value string
                    args[i].type = GetTypeFromName(paramList[i].parenString, context);
                    if (args[i].type != null)

View on GitHub (pinned to 81131a70a4)