AvaloniaUI/Avalonia · error · FormatException

Invalid format. {function} expects {count} value(s).

Error message

Invalid format. {function} expects {count} value(s).

What it means

Thrown by TransformParser.ThrowFormatInvalidValueCount when a transform function is given the wrong number of arguments. The message states the exact count the function expects, e.g. 'Invalid format. scale expects 2 value(s).' This is a count mismatch, distinct from error 325 (too many) which is the raw overflow guard; this is the function-level expectation.

Source

Thrown at src/Avalonia.Base/Media/Transformation/TransformParser.cs:361

                case Unit.Turn:
                {
                    return true;
                }
            }

            return false;
        }

        private static void ThrowFormatInvalidValue(TransformFunction function, in UnitValue value)
        {
            var unitString = value.Unit == Unit.None ? string.Empty : value.Unit.ToString();

            throw new FormatException($"Invalid value {value.Value} {unitString} for {function}");
        }

        private static void ThrowFormatInvalidValueCount(TransformFunction function, int count)
        {
            throw new FormatException($"Invalid format. {function} expects {count} value(s).");
        }

        private static Unit ParseUnit(in ReadOnlySpan<char> part)
        {
            foreach (var (name, unit) in s_unitMapping)
            {
                if (part.Equals(name.AsSpan(), StringComparison.OrdinalIgnoreCase))
                {
                    return unit;
                }
            }

            throw new FormatException($"Invalid unit: {part.ToString()}");
        }

        private static TransformFunction ParseTransformFunction(in ReadOnlySpan<char> part)
        {
            foreach (var (name, transformFunction) in s_functionMapping)

View on GitHub (pinned to 11c5427268)

Solutions

  1. Supply exactly the number of values the message reports the function expects.
  2. Look up the function's required arity in the transform documentation.
  3. If a single-value shorthand is desired, verify the parser supports it; otherwise provide the full argument list.

Example fix

// before
var t = TransformOperations.Parse("translate(10px)"); // if translate expects 2 values

// after
var t = TransformOperations.Parse("translate(10px, 0px)");
Defensive patterns

Strategy: validation

Try / catch

try { return TransformOperations.Parse(s); }
catch (FormatException ex) when (ex.Message.Contains("expects"))
{ /* supply the exact value count from the message */ }

Prevention

When it happens

Trigger: Calling a transform function with fewer arguments than required, e.g. scale(2) where two are needed (depending on function definition), or matrix() with the wrong arity. The function's declared count is checked after parsing and ThrowFormatInvalidValueCount is invoked on mismatch.

Common situations: Hand-authored transforms missing arguments; copy-paste truncation; assuming a single-argument shorthand that the parser does not accept.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/220fc4c3b86bbb3c. Report an issue: GitHub.