{"record":{"id":"12dc297597c48163","repo":"dotnet/wpf","slug":"sr-timing-repeatbehaviorinvaliditerationcount","errorCode":null,"errorMessage":"SR.Timing_RepeatBehaviorInvalidIterationCount","messagePattern":"SR\\.Timing_RepeatBehaviorInvalidIterationCount","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/RepeatBehavior.cs","lineNumber":39,"sourceCode":"    /// <para>A Forever RepeatBehavior specifies that a Timeline will repeat forever.</para>\n    /// </summary>\n    [TypeConverter(typeof(RepeatBehaviorConverter))]\n    public readonly struct RepeatBehavior : IFormattable\n    {\n        private readonly double _iterationCount;\n        private readonly TimeSpan _repeatDuration;\n        private readonly RepeatBehaviorType _type;\n\n        #region Constructors\n\n        /// <summary>\n        /// Creates a new RepeatBehavior that represents and iteration count.\n        /// </summary>\n        /// <param name=\"count\">The number of iterations specified by this RepeatBehavior.</param>\n        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;","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/RepeatBehavior.cs#L21-L57","documentation":"The RepeatBehavior(double count) constructor requires a finite, non-negative iteration count. Passing infinity, NaN, or a negative number throws ArgumentOutOfRangeException with the message Timing_RepeatBehaviorInvalidIterationCount. The constructor is strict because iteration count drives the timing engine and undefined values would corrupt the animation schedule.","triggerScenarios":"new RepeatBehavior(double.PositiveInfinity), new RepeatBehavior(double.NaN), or new RepeatBehavior(-1) — any count that is Infinity, NaN, or < 0.","commonSituations":"Computing a repeat count from division that yields NaN (e.g., 0/0) or Infinity; a config/default value of -1 meaning 'infinite' from another API (use RepeatBehavior.Forever instead); parsing user input without sanitization.","solutions":["Validate count is finite and >= 0 before constructing: double.IsFinite(count) && count >= 0.","For infinite repetition use RepeatBehavior.Forever instead of double.PositiveInfinity.","Clamp or default invalid computed values, e.g. Math.Max(1, count)."],"exampleFix":"// before\nvar rb = new RepeatBehavior(-1); // meant 'forever'\n// after\nvar rb = RepeatBehavior.Forever;","handlingStrategy":"validation","validationCode":"if (!double.IsFinite(count) || count < 0) throw new ArgumentException($\"Invalid repeat count: {count}\");\nvar rb = new RepeatBehavior(count);","typeGuard":"static bool IsValidRepeatCount(double count) => double.IsFinite(count) && count >= 0;","tryCatchPattern":"RepeatBehavior rb;\ntry { rb = new RepeatBehavior(count); }\ncatch (ArgumentOutOfRangeException) { rb = RepeatBehavior.Forever; }","preventionTips":["Use RepeatBehavior.Forever for infinite repetition, never Infinity.","Sanitize computed counts (NaN/Infinity from division) before constructing.","Never use -1 as a 'forever' sentinel across API boundaries."],"tags":["wpf","animation","argument-out-of-range","repeat-behavior"],"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"}