dotnet/wpf · error · ArgumentException

Storyboard_UnrecognizedTimeSeekOrigin

Storyboard_UnrecognizedTimeSeekOrigin

Error message

SR.Storyboard_UnrecognizedTimeSeekOrigin

What it means

The Origin setter of SeekStoryboard validates that the assigned value is exactly TimeSeekOrigin.BeginTime or TimeSeekOrigin.Duration; any other TimeSeekOrigin cast value throws ArgumentException because it is not a recognized seek origin.

Solutions

  1. Only assign TimeSeekOrigin.BeginTime or TimeSeekOrigin.Duration.
  2. Validate the numeric source value before casting to TimeSeekOrigin.
  3. Use Enum.TryParse on the string form and confirm the result is one of the two known values.

Example fix

// before
seek.Origin = (TimeSeekOrigin)enumValue; // may throw

// after
var origin = enumValue == 1 ? TimeSeekOrigin.Duration : TimeSeekOrigin.BeginTime;
seek.Origin = origin;
Defensive patterns

Strategy: validation

Validate before calling

bool valid = origin == TimeSeekOrigin.BeginTime || origin == TimeSeekOrigin.Duration;

Type guard

static bool IsKnownTimeSeekOrigin(TimeSeekOrigin o) => o is TimeSeekOrigin.BeginTime or TimeSeekOrigin.Duration;

Try / catch

try { seek.Origin = parsedOrigin; } catch (ArgumentException ex) { /* fall back to BeginTime */ }

Prevention

When it happens

Trigger: Assigning Origin from an unchecked cast or parsed value, e.g. (TimeSeekOrigin)intValue where intValue is 3+ or negative, or a default(TimeSeekOrigin) of 0.

Common situations: Reading Origin values from configuration/user input and casting without validation; marshaling enum values across component boundaries.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/SeekStoryboard.cs:81

    {
        get
        {
            return _origin;
        }
        set
        {
            if (IsSealed)
            {
                throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, "SeekStoryboard"));
            }

            if( value == TimeSeekOrigin.BeginTime || value == TimeSeekOrigin.Duration ) // FxCop doesn't like Enum.IsDefined, probably need some central validation mechanism.
            {
                _origin = value;
            }
            else
            {
                throw new ArgumentException(SR.Storyboard_UnrecognizedTimeSeekOrigin);
            }
        }
    }

    /// <summary>
    ///     Called when it's time to execute this storyboard action
    /// </summary>
    internal override void Invoke( FrameworkElement containingFE, FrameworkContentElement containingFCE, Storyboard storyboard )
    {
        Debug.Assert( containingFE != null || containingFCE != null,
            "Caller of internal function failed to verify that we have a FE or FCE - we have neither." );

        if( containingFE != null )
        {
            storyboard.Seek(containingFE, Offset, Origin);
        }
        else
        {

View on GitHub (pinned to 81131a70a4)