AvaloniaUI/Avalonia · error · ArgumentException
Unknown CacheMode: {s}
Error message
Unknown CacheMode: {s} What it means
CacheMode.Parse throws an ArgumentException because the parser currently recognizes only the literal string 'BitmapCache'. Any other input is an unknown cache mode. This is a deliberately narrow parser — the only supported cache mode value is BitmapCache.
Source
Thrown at src/Avalonia.Base/Media/CacheMode.cs:19
using System;
using Avalonia.Rendering.Composition;
using Avalonia.Rendering.Composition.Drawing;
namespace Avalonia.Media;
/// <summary>
/// Represents cached content modes for graphics acceleration features.
/// </summary>
public abstract class CacheMode : StyledElement
{
// We currently only allow visual to be attached to one compositor at a time, so keep it simple for now
internal abstract CompositionCacheMode GetForCompositor(Compositor c);
public static CacheMode Parse(string s)
{
if(s == "BitmapCache")
return new BitmapCache();
throw new ArgumentException("Unknown CacheMode: " + s);
}
}View on GitHub (pinned to 11c5427268)
Solutions
- Use exactly "BitmapCache" as the string value.
- If you need other cache modes, construct the specific CacheMode subclass (e.g. new BitmapCache()) directly instead of parsing.
- Validate the string equals "BitmapCache" before calling Parse.
Example fix
// before
var mode = CacheMode.Parse("bitmapCache");
// after
var mode = CacheMode.Parse("BitmapCache");
// or directly:
var mode = new BitmapCache(); Defensive patterns
Strategy: validation
Validate before calling
CacheMode mode = string.Equals(s, "BitmapCache", StringComparison.Ordinal)
? new BitmapCache()
: null; // or a fallback Prevention
- Only pass the exact string "BitmapCache" to CacheMode.Parse.
- Prefer constructing CacheMode subclasses directly over parsing.
- Document that BitmapCache is currently the only supported cache mode.
When it happens
Trigger: Calling CacheMode.Parse(s) where s is anything other than the exact string "BitmapCache" (case-sensitive). E.g. "bitmapcache", "BitmapCacheShading", or a typo.
Common situations: Typo in a XAML CacheMode attribute. Using lowercase or a variant spelling. Attempting to reference a cache mode that does not exist in this version of Avalonia.
Related errors
- Invalid brush string: '{s}'.
- Invalid color string: '{s}'.
- Invalid color string: '{s.ToString()}'.
- Unable to parse effect: {s}
- Specified family is not supported.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/75d172f6436ab2be.
Report an issue: GitHub.