{"record":{"id":"0393c60fb117dab7","repo":"dotnet/wpf","slug":"sr-timing-repeatbehaviorinvalidrepeatduration","errorCode":null,"errorMessage":"SR.Timing_RepeatBehaviorInvalidRepeatDuration","messagePattern":"SR\\.Timing_RepeatBehaviorInvalidRepeatDuration","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/RepeatBehavior.cs","lineNumber":54,"sourceCode":"        public RepeatBehavior(double count)\n        {\n            if (double.IsInfinity(count) || double.IsNaN(count) || count < 0.0)\n                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.Timing_RepeatBehaviorInvalidIterationCount, count));\n\n            _repeatDuration = TimeSpan.Zero;\n            _iterationCount = count;\n            _type = RepeatBehaviorType.IterationCount;\n        }\n\n        /// <summary>\n        /// Creates a new RepeatBehavior that represents a repeat duration for which a Timeline will repeat\n        /// its simple duration.\n        /// </summary>\n        /// <param name=\"duration\">A TimeSpan representing the repeat duration specified by this RepeatBehavior.</param>\n        public RepeatBehavior(TimeSpan duration)\n        {\n            if (duration < TimeSpan.Zero)\n                throw new ArgumentOutOfRangeException(nameof(duration), SR.Format(SR.Timing_RepeatBehaviorInvalidRepeatDuration, duration));\n\n            _iterationCount = 0.0;\n            _repeatDuration = duration;\n            _type = RepeatBehaviorType.RepeatDuration;\n        }\n\n        /// <summary>\n        /// Private constructor, serves for creation of <see cref=\"RepeatBehavior.Forever\"/> only.\n        /// </summary>\n        /// <param name=\"behaviorType\">Only <see cref=\"RepeatBehaviorType.Forever\"/> value is permitted.</param>\n        private RepeatBehavior(RepeatBehaviorType behaviorType)\n        {\n            Debug.Assert(behaviorType == RepeatBehaviorType.Forever);\n\n            _type = behaviorType;\n        }\n\n        #endregion // Constructors","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/RepeatBehavior.cs#L36-L72","documentation":"The RepeatBehavior(TimeSpan duration) constructor rejects negative TimeSpans with ArgumentOutOfRangeException carrying Timing_RepeatBehaviorInvalidRepeatDuration. A repeat duration defines how long the animation repeats, and a negative duration is meaningless to the timing engine.","triggerScenarios":"new RepeatBehavior(TimeSpan.FromSeconds(-5)) or computing the duration from a value that can go negative (e.g., endTime - startTime where the inputs were reversed).","commonSituations":"Subtracting DateTime/TimeSpan endpoints in the wrong order; loading a negative duration from config or user input; converting seconds to TimeSpan with a negative multiplier.","solutions":["Check duration >= TimeSpan.Zero before constructing (use TimeSpan.Compare or the >= operator).","Clamp with duration < TimeSpan.Zero ? TimeSpan.Zero : duration.","If you need zero-length repeat, pass TimeSpan.Zero; if infinite, use RepeatBehavior.Forever."],"exampleFix":"// before\nvar rb = new RepeatBehavior(end - start); // end < start\n// after\nvar dur = end - start;\nvar rb = new RepeatBehavior(dur >= TimeSpan.Zero ? dur : TimeSpan.Zero);","handlingStrategy":"validation","validationCode":"if (duration < TimeSpan.Zero) duration = TimeSpan.Zero;\nvar rb = new RepeatBehavior(duration);","typeGuard":"static bool IsValidRepeatDuration(TimeSpan d) => d >= TimeSpan.Zero;","tryCatchPattern":"RepeatBehavior rb;\ntry { rb = new RepeatBehavior(duration); }\ncatch (ArgumentOutOfRangeException) { rb = new RepeatBehavior(TimeSpan.Zero); }","preventionTips":["Clamp computed durations to TimeSpan.Zero when subtracting ordered time points.","Double-check subtraction order when deriving duration from end - start.","Validate config/user-supplied durations at load time."],"tags":["wpf","animation","argument-out-of-range","timespan"],"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"}