dotnet/wpf · error · InvalidOperationException

SR.Format(SR.PropertyPathSyntaxError, detail)

Error message

SR.Format(SR.PropertyPathSyntaxError, detail)

What it means

PropertyPath builds source-value info from its parsed path; if the parser produced no path steps (_arySVI.Length == 0), the path string itself is syntactically invalid. The exception surfaces the parser's error detail (or the raw Path) to indicate the syntax problem.

Solutions

  1. Fix the path string syntax (valid form: PropertyName.SubProp[Index].(AttachedType.Prop)).
  2. Validate the path against the target object's actual property names.
  3. Use non-empty path or Path='.' for self-reference.
  4. Test the binding with a known-good simple path, then build up complexity.

Example fix

// before
binding.Path = new PropertyPath("(Panel.ZIndex"); // unbalanced paren
// after
binding.Path = new PropertyPath("(Panel.ZIndex)");
Defensive patterns

Strategy: validation

Validate before calling

bool pathLooksValid(string p) => !string.IsNullOrWhiteSpace(p) &&
    p.Count(c => c == '(') == p.Count(c => c == ')') &&
    p.Count(c => c == '[') == p.Count(c => c == ']');

Type guard

bool HasSteps(PropertyPath pp) => pp != null && pp.PathParameters != null; // plus catch at bind time
bool IsValidPathString(string p) => pathLooksValid(p);

Try / catch

try { binding.Path = new PropertyPath(pathString); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Syntax"))
{ Trace.WriteLine($"Bad PropertyPath: {pathString}"); }

Prevention

When it happens

Trigger: Binding or storyboard targeting with a malformed PropertyPath string — e.g. empty path, unbalanced parentheses/brackets, bad indexer syntax, invalid leading characters — so the parser yields zero steps.

Common situations: Typo in binding Path like '()()' or '[', paths constructed programmatically with new PropertyPath(""), localized/generated path strings corrupted, WPF property paths copied from other frameworks (different syntax).

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

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

        //------------------------------------------------------
        //
        //  Private methods
        //
        //------------------------------------------------------

        // parse the path to figure out what kind of
        // SourceValueInfo we're going to need
        private void PrepareSourceValueInfo(ITypeDescriptorContext typeDescriptorContext)
        {
            PathParser parser = DataBindEngine.CurrentDataBindEngine.PathParser;
            _arySVI = parser.Parse(Path);

            if (_arySVI.Length == 0)
            {
                string detail = parser.Error;
                if (detail == null)
                    detail = Path;
                throw new InvalidOperationException(SR.Format(SR.PropertyPathSyntaxError, detail));
            }

            ResolvePathParts(typeDescriptorContext);
        }

        // "normalize" the path - i.e. load the PathParameters with the early-bound
        // accessors, and replace the corresponding parts of the path with
        // parameter references
        private void NormalizePath()
        {
            StringBuilder builder = new StringBuilder();
            PathParameterCollection parameters = new PathParameterCollection();

            for (int i=0; i<_arySVI.Length; ++i)
            {
                switch (_arySVI[i].drillIn)
                {
                    case DrillIn.Always:

View on GitHub (pinned to 81131a70a4)