AvaloniaUI/Avalonia · error · NotSupportedException

Gradient of type {gradientBrush?.GetType()} is not supported

Error message

Gradient of type {gradientBrush?.GetType()} is not supported

What it means

Thrown by GradientBrushAnimator interpolation when the old brush is a gradient type that the animator does not handle. The default case covers any IGradientBrush that is neither a conic nor a linear gradient brush (e.g. a radial gradient), which this animator cannot interpolate.

Source

Thrown at src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs:150

                        oldRadial.SpreadMethod, oldRadial.Center, oldRadial.GradientOrigin,
                        oldRadial.RadiusX, oldRadial.RadiusY);

                case IConicGradientBrush oldConic:
                    return new ImmutableConicGradientBrush(
                        CreateStopsFromSolidColorBrush(solidColorBrush, oldConic.GradientStops), solidColorBrush.Opacity,
                        oldConic.Transform is { } ? new ImmutableTransform(oldConic.Transform.Value) : null,
                        oldConic.TransformOrigin,
                        oldConic.SpreadMethod, oldConic.Center, oldConic.Angle);

                case ILinearGradientBrush oldLinear:
                    return new ImmutableLinearGradientBrush(
                        CreateStopsFromSolidColorBrush(solidColorBrush, oldLinear.GradientStops), solidColorBrush.Opacity,
                        oldLinear.Transform is { } ? new ImmutableTransform(oldLinear.Transform.Value) : null,
                        oldLinear.TransformOrigin,
                        oldLinear.SpreadMethod, oldLinear.StartPoint, oldLinear.EndPoint);

                default:
                    throw new NotSupportedException($"Gradient of type {gradientBrush?.GetType()} is not supported");
            }

            static IReadOnlyList<ImmutableGradientStop> CreateStopsFromSolidColorBrush(ISolidColorBrush solidColorBrush, IReadOnlyList<IGradientStop> baseStops)
            {
                var stops = new ImmutableGradientStop[baseStops.Count];
                for (int index = 0; index < baseStops.Count; index++)
                {
                    stops[index] = new ImmutableGradientStop(baseStops[index].Offset, solidColorBrush.Color);
                }
                return stops;
            }
        }
    }
}

View on GitHub (pinned to 11c5427268)

Solutions

  1. Animate only Linear or Conic gradient brushes with GradientBrushAnimator.
  2. Avoid animating across incompatible brush kinds; settle the target to a supported gradient type first.
  3. Use SolidColorBrushAnimator when animating solid color brushes.

Example fix

// before
control.Background = new RadialGradientBrush(...); // then gradient-animated

// after
control.Background = new LinearGradientBrush(...); // supported gradient type
Defensive patterns

Strategy: validation

Validate before calling

if (control.Background is IRadialGradientBrush)
    throw new NotSupportedException("RadialGradientBrush is not supported by GradientBrushAnimator.");

Type guard

static bool IsSupportedGradient(IBrush? b) => b is ILinearGradientBrush or IConicGradientBrush;

Prevention

When it happens

Trigger: Interpolating toward/away from an IGradientBrush whose concrete type is not IConicGradientBrush or ILinearGradientBrush (notably IRadialGradientBrush).

Common situations: Switching a control's background from a RadialGradientBrush to a solid/linear brush while a gradient animation is active; animating a property that can hold arbitrary IBrush values.

Related errors


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