dotnet/wpf · error · InvalidOperationException

Timing_SeekDestinationIndefinite

Timing_SeekDestinationIndefinite

Error message

SR.Timing_SeekDestinationIndefinite (Timing_SeekDestinationIndefinite)

What it means

ClockController.Seek with TimeSeekOrigin.Duration adds the offset to the clock's resolved duration. If that duration is Forever or not yet resolved (no TimeSpan), there is no numeric duration to be relative to, so WPF throws InvalidOperationException (Timing_SeekDestinationIndefinite).

Solutions

  1. Use TimeSeekOrigin.Begin instead of Duration when the duration may be indefinite
  2. Ensure the timeline has a concrete TimeSpan Duration before seeking relative to Duration
  3. Check _owner.ResolvedDuration.HasTimeSpan before seeking and branch accordingly
  4. Start the clock (Begin) and let it resolve duration before performing duration-relative seeks

Example fix

// before
if (duration == Duration.Forever)
    controller.Seek(TimeSpan.FromSeconds(2), TimeSeekOrigin.Duration); // throws
// after
if (controller != null)
    controller.Seek(TimeSpan.FromSeconds(2), TimeSeekOrigin.Begin); // relative to start always works
Defensive patterns

Strategy: validation

Validate before calling

if (origin == TimeSeekOrigin.Duration && !clock.ResolvedDuration.HasTimeSpan)
    origin = TimeSeekOrigin.Begin; // safe fallback

Try / catch

try { controller.Seek(offset, TimeSeekOrigin.Duration); }
catch (InvalidOperationException) { controller.Seek(offset, TimeSeekOrigin.Begin); }

Prevention

When it happens

Trigger: controller.Seek(offset, TimeSeekOrigin.Duration) where the owning timeline's ResolvedDuration has no TimeSpan — Duration="Forever", or the clock hasn't been started/resolved yet (duration still Automatic/unresolved).

Common situations: Seeking relative to Duration on a storyboard declared with Duration="Forever" or with no explicit Duration before resolution; interactive seek logic invoked before Begin/first tick resolved the clock.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/291231ce06ca388b. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/ClockController.cs:167

            // IF YOU CHANGE THIS CODE:
            // This code is very similar to that in SeekAlignedToLastTick and is duplicated
            // in each method so that exceptions will be thrown from the public 
            // method the user has called. You probably need to change both methods.

            if (!TimeEnumHelper.IsValidTimeSeekOrigin(origin))
            {
                throw new InvalidEnumArgumentException(SR.Format(SR.Enum_Invalid, "TimeSeekOrigin"));
            }

            if (origin == TimeSeekOrigin.Duration)
            {
                Duration duration = _owner.ResolvedDuration;

                if (!duration.HasTimeSpan)
                {
                    // Can't seek relative to the Duration if it has been specified as Forever or if
                    // it has not yet been resolved.
                    throw new InvalidOperationException(SR.Timing_SeekDestinationIndefinite);
                }
                else
                {
                    offset += duration.TimeSpan;
                }
            }

            // Any offset greater than zero is OK here. If it's past the effective
            // duration it means execute the FillBehavior.
            if (offset < TimeSpan.Zero)
            {
                throw new InvalidOperationException(SR.Timing_SeekDestinationNegative);
            }

            _owner.InternalSeek(offset);
        }

        /// <summary>

View on GitHub (pinned to 81131a70a4)