{"record":{"id":"bff66015e020e8ff","repo":"AvaloniaUI/Avalonia","slug":"unable-to-parse-effect-s","errorCode":null,"errorMessage":"Unable to parse effect: {s}","messagePattern":"Unable to parse effect: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/Effects/Effect.cs","lineNumber":43,"sourceCode":"            static e => (e.Sender as T)?.RaiseInvalidated(EventArgs.Empty));\n\n        foreach (var property in properties)\n        {\n            property.Changed.Subscribe(invalidateObserver);\n        }\n    }\n\n    /// <summary>\n    /// Raises the <see cref=\"Invalidated\"/> event.\n    /// </summary>\n    /// <param name=\"e\">The event args.</param>\n    protected void RaiseInvalidated(EventArgs e) => Invalidated?.Invoke(this, e);\n\n    /// <inheritdoc />\n    public event EventHandler? Invalidated;\n\n\n    static Exception ParseError(string s) => throw new ArgumentException(\"Unable to parse effect: \" + s);\n    public static IEffect Parse(string s)\n    {\n        var span = s.AsSpan();\n        var r = new TokenParser(span);\n        if (r.TryConsume(\"blur\"))\n        {\n            if (!r.TryConsume('(') || !r.TryParseDouble(out var radius) || !r.TryConsume(')') || !r.IsEofWithWhitespace())\n                throw ParseError(s);\n            return new ImmutableBlurEffect(radius);\n        }\n\n       \n        if (r.TryConsume(\"drop-shadow\"))\n        {\n            if (!r.TryConsume('(') || !r.TryParseDouble(out var offsetX)\n                                   || !r.TryParseDouble(out var offsetY))\n                throw ParseError(s);\n            double blurRadius = 0;","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/Effects/Effect.cs#L25-L61","documentation":"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)'.","triggerScenarios":"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 ')'.","commonSituations":"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.","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."],"exampleFix":"// before\nvar effect = Effect.Parse(\"dropshadow(2)\");\n\n// after\nvar effect = new BlurEffect { Radius = 5 };\n// or parse valid syntax:\nvar effect = Effect.Parse(\"blur(5)\");","handlingStrategy":"validation","validationCode":"IEffect effect;\nif (s.StartsWith(\"blur(\", StringComparison.Ordinal) && s.EndsWith(\")\"))\n    effect = Effect.Parse(s);\nelse\n    effect = null; // or construct a known effect directly","typeGuard":null,"tryCatchPattern":"IEffect effect;\ntry { effect = Effect.Parse(s); }\ncatch (ArgumentException) { effect = null; }","preventionTips":["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."],"tags":["effect","parsing","media","blur"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}