AvaloniaUI/Avalonia · error · ArgumentException

'{defaultValue}' is not a valid default value for '{property

Error message

'{defaultValue}' is not a valid default value for '{propertyName}'.

What it means

Error "'{defaultValue}' is not a valid default value for '{propertyName}'." thrown in AvaloniaUI/Avalonia.

Source

Thrown at src/Avalonia.Base/StyledPropertyNonGenericHelper.cs:26

/// Contains methods for <see cref="StyledProperty{TValue}"/> that aren't using generic arguments.
/// Separated to avoid unnecessary generic instantiations.
/// </summary>
internal static class StyledPropertyNonGenericHelper
{
    [DoesNotReturn]
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static void ThrowInvalidValue(string propertyName, object? value, string paramName)
    {
        var type = value?.GetType().FullName ?? "(null)";

        throw new ArgumentException(
            $"Invalid value for Property '{propertyName}': '{value}' ({type})",
            paramName);
    }

    public static void ThrowInvalidDefaultValue(string propertyName, object? defaultValue, string paramName)
    {
        throw new ArgumentException(
            $"'{defaultValue}' is not a valid default value for '{propertyName}'.",
            paramName);
    }
}

View on GitHub (pinned to 11c5427268)

Solutions

  1. Change the registered default value to one that is valid for the property's type and validation.
  2. Register the property with the correct value type so the default value is assignable.

When it happens

Trigger: Raised when a styled property is registered with a default value that is not valid for the property's type. Defend by supplying default values of the correct type at registration and catching mismatches in registration-time validation.

Common situations: See trigger scenarios.


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