AvaloniaUI/Avalonia · error · FormatException

Could not parse specified Unicode range.

Error message

Could not parse specified Unicode range.

What it means

Thrown by UnicodeRange.Parse when the input string s is null or empty. UnicodeRange.Parse expects a comma-separated list of range segments (e.g. 'U+20-7F, U+100'). An empty/null input has no segments to parse and is rejected with a FormatException.

Source

Thrown at src/Avalonia.Base/Media/UnicodeRange.cs:77

                {
                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// Parses a <see cref="UnicodeRange"/>.
        /// </summary>
        /// <param name="s">The string to parse.</param>
        /// <returns>The parsed <see cref="UnicodeRange"/>.</returns>
        /// <exception cref="FormatException"></exception>
        public static UnicodeRange Parse(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                throw new FormatException("Could not parse specified Unicode range.");
            }

            var parts = s.Split(',');

            var length = parts.Length;

            if(length == 0)
            {
                throw new FormatException("Could not parse specified Unicode range.");
            }

            if(length == 1)
            {
                return new UnicodeRange(UnicodeRangeSegment.Parse(parts[0]));
            }

            var segments = new UnicodeRangeSegment[length];

View on GitHub (pinned to 11c5427268)

Solutions

  1. Provide a non-empty unicode-range string such as 'U+0000-007F'.
  2. Guard the call: if (string.IsNullOrEmpty(s)) return UnicodeRange.AllRanges (or a sensible default) instead of calling Parse.
  3. Ensure the data source always supplies a value.

Example fix

// before
var range = UnicodeRange.Parse(value); // throws when value is null/empty

// after
var range = string.IsNullOrEmpty(value) ? UnicodeRange.AllRanges : UnicodeRange.Parse(value);
Defensive patterns

Strategy: validation

Validate before calling

static UnicodeRange SafeParseRange(string s)
    => string.IsNullOrEmpty(s) ? UnicodeRange.AllRanges : UnicodeRange.Parse(s);

Try / catch

try { return UnicodeRange.Parse(s); }
catch (FormatException) { return UnicodeRange.AllRanges; }

Prevention

When it happens

Trigger: Calling UnicodeRange.Parse(null) or UnicodeRange.Parse(""). This is the first guard in Parse, before splitting on commas. The identical message is reused at line 86 for a different (defensive) condition.

Common situations: Deserializing a unicode-range from CSS/config where the field is absent and resolves to null/empty; passing an unset property; a binding that did not resolve.

Related errors


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