{"record":{"id":"5ca8324335dd8417","repo":"dotnet/wpf","slug":"timing-seekdestinationnegative","errorCode":"Timing_SeekDestinationNegative","errorMessage":"SR.Timing_SeekDestinationNegative (Timing_SeekDestinationNegative)","messagePattern":"SR\\.Timing_SeekDestinationNegative \\(Timing_SeekDestinationNegative\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/ClockController.cs","lineNumber":179,"sourceCode":"                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\n            // Any offset greater than zero is OK here. If it's past the effective\n            // duration it means execute the FillBehavior.\n            if (offset < TimeSpan.Zero)\n            {\n                throw new InvalidOperationException(SR.Timing_SeekDestinationNegative);\n            }\n\n            _owner.InternalSeek(offset);\n        }\n\n        /// <summary>\n        /// Process all information that occured until now\n        /// </summary>\n\n        public void SeekAlignedToLastTick(TimeSpan offset, TimeSeekOrigin origin)\n        {\n            // IF YOU CHANGE THIS CODE:\n            // This code is very similar to that in Seek 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            {","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/ClockController.cs#L161-L197","documentation":"ClockController.Seek computes the absolute destination time and rejects negative results. A negative offset (e.g. seeking before the timeline's start) is not a representable clock time, so WPF throws InvalidOperationException (Timing_SeekDestinationNegative).","triggerScenarios":"controller.Seek(negativeTimeSpan, TimeSeekOrigin.Begin), or Seek(offset, TimeSeekOrigin.Duration) where offset is negative and larger than the resolved duration (offset + duration < 0).","commonSituations":"Computed seek targets from user input, playback scrubbing, or bookmark/progress arithmetic that can go below zero (e.g. rewinding further than elapsed time).","solutions":["Clamp the computed offset: Math.Max(offset, TimeSpan.Zero)","Validate the target time before calling Seek and skip the call if negative","When seeking relative to Duration, ensure offset magnitude does not exceed the duration"],"exampleFix":"// before\ncontroller.Seek(elapsed - rewindAmount, TimeSeekOrigin.Begin); // throws if negative\n// after\nvar target = elapsed - rewindAmount;\ncontroller.Seek(target < TimeSpan.Zero ? TimeSpan.Zero : target, TimeSeekOrigin.Begin);","handlingStrategy":"validation","validationCode":"if (offset < TimeSpan.Zero) offset = TimeSpan.Zero;\ncontroller.Seek(offset, origin);","typeGuard":null,"tryCatchPattern":"try { controller.Seek(offset, origin); }\ncatch (InvalidOperationException ex) when (offset < TimeSpan.Zero) { controller.Seek(TimeSpan.Zero, origin); }","preventionTips":["Clamp computed seek targets with Math.Max(target, TimeSpan.Zero)","Validate user/scrubber input ranges before applying deltas","Treat TimeSpan arithmetic results as potentially negative and normalize"],"tags":["wpf","animation","seek","out-of-range"],"backgroundTag":"argument-out-of-range","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"}