AvaloniaUI/Avalonia · error · ArgumentException
Unable to parse effect: {s}
Error message
Unable to parse effect: {s} What it means
Effect.Parse throws an ArgumentException when the input does not match a supported effect grammar. Currently the parser recognizes 'blur(<radius>)' syntax; any other leading token, malformed parenthesis, non-numeric radius, or trailing characters trigger the error. Note ParseError is defined as a method that always throws, used via 'throw ParseError(s)'.
Source
Thrown at src/Avalonia.Base/Media/Effects/Effect.cs:43
static e => (e.Sender as T)?.RaiseInvalidated(EventArgs.Empty));
foreach (var property in properties)
{
property.Changed.Subscribe(invalidateObserver);
}
}
/// <summary>
/// Raises the <see cref="Invalidated"/> event.
/// </summary>
/// <param name="e">The event args.</param>
protected void RaiseInvalidated(EventArgs e) => Invalidated?.Invoke(this, e);
/// <inheritdoc />
public event EventHandler? Invalidated;
static Exception ParseError(string s) => throw new ArgumentException("Unable to parse effect: " + s);
public static IEffect Parse(string s)
{
var span = s.AsSpan();
var r = new TokenParser(span);
if (r.TryConsume("blur"))
{
if (!r.TryConsume('(') || !r.TryParseDouble(out var radius) || !r.TryConsume(')') || !r.IsEofWithWhitespace())
throw ParseError(s);
return new ImmutableBlurEffect(radius);
}
if (r.TryConsume("drop-shadow"))
{
if (!r.TryConsume('(') || !r.TryParseDouble(out var offsetX)
|| !r.TryParseDouble(out var offsetY))
throw ParseError(s);
double blurRadius = 0;View on GitHub (pinned to 11c5427268)
Solutions
- Use the exact supported syntax: "blur(<number>)" e.g. "blur(5)".
- For other effects, construct the effect object directly (e.g. new BlurEffect { Radius = 5 }) instead of parsing a string.
- Validate the string matches the blur pattern before parsing.
Example fix
// before
var effect = Effect.Parse("dropshadow(2)");
// after
var effect = new BlurEffect { Radius = 5 };
// or parse valid syntax:
var effect = Effect.Parse("blur(5)"); Defensive patterns
Strategy: validation
Validate before calling
IEffect effect;
if (s.StartsWith("blur(", StringComparison.Ordinal) && s.EndsWith(")"))
effect = Effect.Parse(s);
else
effect = null; // or construct a known effect directly Try / catch
IEffect effect;
try { effect = Effect.Parse(s); }
catch (ArgumentException) { effect = null; } Prevention
- Only use the supported "blur(<radius>)" syntax for Effect.Parse.
- Construct effect objects directly (e.g. new BlurEffect) for clarity.
- Validate user-supplied effect strings before parsing.
When it happens
Trigger: Calling Effect.Parse(s) where s does not start with 'blur(' followed by a valid double radius and ')'. E.g. "dropshadow(5)", "blur()", "blur(abc)", "blur(5". The parser uses a TokenParser and is strict about consuming '(' double ')'.
Common situations: Trying to use WPF-style effect syntax not supported by Avalonia (e.g. drop shadow via string). Typo in the effect keyword. Missing or malformed parentheses/radius. Expecting a richer effect DSL than what exists.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Invalid brush string: '{s}'.
- Unknown CacheMode: {s}
- Invalid color string: '{s}'.
- Invalid color string: '{s.ToString()}'.
- Specified family is not supported.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/bff66015e020e8ff.
Report an issue: GitHub.