AvaloniaUI/Avalonia · error · ArgumentException
Invalid value
Error message
Invalid value
What it means
Thrown by the IterationCount(ulong, IterationType) constructor when the type argument is an invalid enum value greater than IterationType.Infinite. IterationType is { Many=0, Infinite=1 }, so any other numeric value is rejected.
Source
Thrown at src/Avalonia.Base/Animation/IterationCount.cs:44
/// <summary>
/// Initializes a new instance of the <see cref="IterationCount"/> struct.
/// </summary>
/// <param name="value">The number of iterations of an animation.</param>
public IterationCount(ulong value)
: this(value, IterationType.Many)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="IterationCount"/> struct.
/// </summary>
/// <param name="value">The size of the IterationCount.</param>
/// <param name="type">The unit of the IterationCount.</param>
public IterationCount(ulong value, IterationType type)
{
if (type > IterationType.Infinite)
{
throw new ArgumentException("Invalid value", nameof(type));
}
_type = type;
_value = value;
}
/// <summary>
/// Gets an instance of <see cref="IterationCount"/> that indicates that an animation
/// should repeat forever.
/// </summary>
public static IterationCount Infinite => new IterationCount(0, IterationType.Infinite);
/// <summary>
/// Gets the unit of the <see cref="IterationCount"/>.
/// </summary>
public IterationType RepeatType => _type;
/// <summary>View on GitHub (pinned to 11c5427268)
Solutions
- Use only IterationType.Many or IterationType.Infinite.
- Validate the enum with Enum.IsDefined before constructing.
- Prefer IterationCount.Infinite or new IterationCount(n) helpers over the two-arg constructor.
Example fix
// before var ic = new IterationCount(3, (IterationType)5); // after var ic = new IterationCount(3, IterationType.Many);
Defensive patterns
Strategy: validation
Validate before calling
if (!Enum.IsDefined(typeof(IterationType), type))
throw new ArgumentException("Invalid IterationType.", nameof(type)); Type guard
static bool IsValidIterationType(IterationType t) => Enum.IsDefined(typeof(IterationType), t);
Prevention
- Use only IterationType.Many or IterationType.Infinite.
- Validate with Enum.IsDefined before constructing from a cast/external value.
- Prefer the IterationCount(ulong) or IterationCount.Infinite helpers.
When it happens
Trigger: Constructing new IterationCount(value, (IterationType)99) or otherwise casting an out-of-range integer to IterationType.
Common situations: Casting an arbitrary int to IterationType without validation; deserializing a numeric enum value outside the defined range.
Related errors
- IterationCount can't be a negative number.
- Unknown PlaybackBehavior value: {_playbackBehavior}
- Duration value cannot be negative.
- DelayBetweenIterations value cannot be negative.
- IterationCount value cannot be larger than long.MaxValue.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/e38bb809a9f00782.
Report an issue: GitHub.