{"record":{"id":"09dfd86aec7ad96d","repo":"dotnet/wpf","slug":"enum-invalid","errorCode":"Enum_Invalid","errorMessage":"SR.Enum_Invalid: TimeSeekOrigin","messagePattern":"SR\\.Enum_Invalid: TimeSeekOrigin","errorType":"exception","errorClass":"InvalidEnumArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/ClockController.cs","lineNumber":156,"sourceCode":"        /// <p>The seek is measured in the Clock's simple time frame of reference, meaning that the\n        /// actual wall-clock playback time skipped (or replayed) may be different than that specified\n        /// by the offset parameter, if time manipulations from the Speed, Acceleration or Deceleration\n        /// properties are in effect for this Clock.</p>\n        ///\n        /// <p>The seek operation may only span the current simple duration of the Clock. Seeking to a\n        /// time earlier than the begin time positions the Clock at the begin point, whereas\n        /// seeking beyond the end simply puts the Clock at the end point.</p>\n        /// </remarks>\n        public void Seek(TimeSpan offset, TimeSeekOrigin origin)\n        {\n            // IF YOU CHANGE THIS CODE:\n            // This code is very similar to that in SeekAlignedToLastTick and is duplicated\n            // in each method so that exceptions will be thrown from the public \n            // method the user has called. You probably need to change both methods.\n\n            if (!TimeEnumHelper.IsValidTimeSeekOrigin(origin))\n            {\n                throw new InvalidEnumArgumentException(SR.Format(SR.Enum_Invalid, \"TimeSeekOrigin\"));\n            }\n\n            if (origin == TimeSeekOrigin.Duration)\n            {\n                Duration duration = _owner.ResolvedDuration;\n\n                if (!duration.HasTimeSpan)\n                {\n                    // Can't seek relative to the Duration if it has been specified as Forever or if\n                    // it has not yet been resolved.\n                    throw new InvalidOperationException(SR.Timing_SeekDestinationIndefinite);\n                }\n                else\n                {\n                    offset += duration.TimeSpan;\n                }\n            }\n","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/ClockController.cs#L138-L174","documentation":"ClockController.Seek validates the TimeSeekOrigin enum argument before using it. Passing a value outside TimeSeekOrigin.Begin/Duration raises InvalidEnumArgumentException with SR.Enum_Invalid formatted with \"TimeSeekOrigin\". This is standard enum-argument validation so the exception is thrown from the public method actually called.","triggerScenarios":"Calling clock.Controller.Seek(offset, (TimeSeekOrigin)someInvalidInt) — e.g. casting an arbitrary int, deserializing a bad enum value, or passing TimeSeekOrigin values from a different enum type.","commonSituations":"Enum values persisted in config/XAML/bindings and cast back without validation; code generated from stale metadata where TimeSeekOrigin gained/lost members.","solutions":["Pass only TimeSeekOrigin.Begin or TimeSeekOrigin.Duration","Validate the origin with TimeEnumHelper.IsValidTimeSeekOrigin(origin) or Enum.IsDefined before calling","Fix the cast/source that produced the out-of-range enum value"],"exampleFix":"// before\ncontroller.Seek(TimeSpan.FromSeconds(1), (TimeSeekOrigin)42); // throws\n// after\nvar origin = TimeSeekOrigin.Duration;\nif (TimeEnumHelper.IsValidTimeSeekOrigin(origin))\n    controller.Seek(TimeSpan.FromSeconds(1), origin);","handlingStrategy":"validation","validationCode":"bool isValidOrigin = origin == TimeSeekOrigin.Begin || origin == TimeSeekOrigin.Duration;\n// or: Enum.IsDefined(typeof(TimeSeekOrigin), origin)","typeGuard":"static bool IsValidTimeSeekOrigin(object o) => o is TimeSeekOrigin t && (t == TimeSeekOrigin.Begin || t == TimeSeekOrigin.Duration);","tryCatchPattern":"try { controller.Seek(offset, origin); }\ncatch (System.ComponentModel.InvalidEnumArgumentException ex) { /* fix/normalize origin */ }","preventionTips":["Never cast raw ints to TimeSeekOrigin without Enum.IsDefined","Validate enum values loaded from config/persistence before use","Use a switch on TimeSeekOrigin so unhandled values fail at compile/analysis time"],"tags":["wpf","animation","enum","argument-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}