AvaloniaUI/Avalonia · error · ArgumentException
Minimum allowed value is 1ms and maximum allowed value is 24
Error message
Minimum allowed value is 1ms and maximum allowed value is 24 days.
What it means
Thrown by the KeyFrameAnimation.Duration setter when the duration is outside [1ms, 1 day]. NOTE: the source has two bugs — it validates the OLD _duration field instead of the incoming value (so the check rarely triggers as intended), and it compares against TimeSpan.FromDays(1) while the message and XML doc claim 24 days. The intended contract is: an animation duration must be at least 1ms and at most ~24 days.
Source
Thrown at src/Avalonia.Base/Rendering/Composition/Animations/KeyFrameAnimation.cs:49
/// <summary>
/// The direction the animation is playing.
/// The Direction property allows you to drive your animation from start to end or end to start or alternate
/// between start and end or end to start if animation has an <see cref="IterationCount"/> greater than one.
/// This gives an easy way for customizing animation definitions.
/// </summary>
public PlaybackDirection Direction { get; set; }
/// <summary>
/// The duration of the animation.
/// Minimum allowed value is 1ms and maximum allowed value is 24 days.
/// </summary>
public TimeSpan Duration
{
get => _duration;
set
{
if (_duration < TimeSpan.FromMilliseconds(1) || _duration > TimeSpan.FromDays(1))
throw new ArgumentException("Minimum allowed value is 1ms and maximum allowed value is 24 days.");
_duration = value;
}
}
/// <summary>
/// The iteration behavior for the key frame animation.
/// </summary>
public AnimationIterationBehavior IterationBehavior { get; set; }
/// <summary>
/// The number of times to repeat the key frame animation.
/// </summary>
public int IterationCount { get; set; } = 1;
/// <summary>
/// Specifies how to set the property value when animation is stopped
/// </summary>
public AnimationStopBehavior StopBehavior { get; set; }View on GitHub (pinned to 11c5427268)
Solutions
- Clamp your Duration to at least TimeSpan.FromMilliseconds(1).
- Keep Duration under TimeSpan.FromDays(1) until the upstream bug (wrong variable + FromDays(1) vs 24 days) is fixed.
- If you maintain this library, fix the guard to validate value: if (value < ... || value > ...).
Example fix
// before
anim.Duration = TimeSpan.FromSeconds(0); // intended to throw, may not due to _duration bug
// after
anim.Duration = TimeSpan.FromMilliseconds(16);
// library fix (recommended):
// get => _duration;
// set {
// if (value < TimeSpan.FromMilliseconds(1) || value > TimeSpan.FromDays(24))
// throw new ArgumentException("Minimum allowed value is 1ms and maximum allowed value is 24 days.");
// _duration = value;
// } Defensive patterns
Strategy: validation
Validate before calling
var safe = value < TimeSpan.FromMilliseconds(1) ? TimeSpan.FromMilliseconds(1)
: value > TimeSpan.FromDays(1) ? TimeSpan.FromDays(1)
: value;
anim.Duration = safe; Prevention
- Clamp durations to >= 1ms and <= 1 day (the documented 24-day ceiling is not enforced by the buggy code).
- Watch for the upstream bug: the setter validates _duration not value — file/track the fix.
- Never assign TimeSpan.Zero or a negative duration to an animation.
When it happens
Trigger: Setting animation.Duration to a value < 1ms or, per the literal code, a value that makes the existing _duration fall outside 1ms..1day. Because the wrong variable is checked, the throw is erratic — most invalid assignments silently succeed while a later valid assignment can throw based on the prior value.
Common situations: Setting Duration to TimeSpan.Zero or a negative TimeSpan; computing duration from a user value of 0; relying on the documented 24-day ceiling but actually being capped at 1 day by the buggy check.
Related errors
- Invalid animation duration
- Key frame key
- Key frame key {key} is less than the previous one
- Duration value cannot be negative.
- DelayBetweenIterations value cannot be negative.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/56ccb5bf03089bc1.
Report an issue: GitHub.