AvaloniaUI/Avalonia · error · ArgumentException

s

Error message

s

What it means

Thrown by TransformParser.Parse when the input string s is null or empty. This is a precondition ArgumentException that fires before any parsing logic. It is distinct from the FormatException (error 323) which covers syntactically invalid but non-empty strings. The thrown argument name is 's'.

Source

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

        private static readonly (string, Unit)[] s_unitMapping =
        {
            ("deg", Unit.Degree),
            ("grad", Unit.Gradian),
            ("rad", Unit.Radian),
            ("turn", Unit.Turn), 
            ("px", Unit.Pixel)
        };

        public static TransformOperations Parse(string s)
        {
            void ThrowInvalidFormat()
            {
                throw new FormatException($"Invalid transform string: '{s}'.");
            }

            if (string.IsNullOrEmpty(s))
            {
                throw new ArgumentException(nameof(s));
            }

            var span = s.AsSpan().Trim();

            if (span.Equals("none".AsSpan(), StringComparison.OrdinalIgnoreCase))
            {
                return TransformOperations.Identity;
            }

            var builder = TransformOperations.CreateBuilder(0);

            while (true)
            {
                var beginIndex = span.IndexOf('(');
                var endIndex = span.IndexOf(')');

                if (beginIndex == -1 || endIndex == -1)
                {

View on GitHub (pinned to 11c5427268)

Solutions

  1. Handle null/empty input explicitly before calling Parse — treat null or empty as Identity (the parser's 'none' semantics).
  2. Ensure the data source (config/binding) always provides a value or coalesce empty to 'none'.
  3. Wrap with a null-coalescing: TransformOperations.Parse(s ?? "none").

Example fix

// before
var t = TransformOperations.Parse(maybeNullString); // throws ArgumentException

// after
var t = TransformOperations.Parse(string.IsNullOrEmpty(maybeNullString) ? "none" : maybeNullString);
Defensive patterns

Strategy: validation

Validate before calling

static TransformOperations SafeParseTransform(string s)
    => string.IsNullOrEmpty(s) ? TransformOperations.Identity : TransformOperations.Parse(s);

Prevention

When it happens

Trigger: Calling TransformOperations.Parse(null) or TransformOperations.Parse(string.Empty). This may happen when the transform value comes from a binding or config that resolves to null/empty instead of the expected 'none' keyword.

Common situations: A style/binding that fails to resolve and yields null passed into Parse; a deserialization path that defaults missing fields to empty string; calling Parse on an unset property before initialization.

Related errors


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