{"record":{"id":"e67463a79a70c320","repo":"dotnet/wpf","slug":"sr-animation-unrecognizedhandoffbehavior","errorCode":null,"errorMessage":"SR.Animation_UnrecognizedHandoffBehavior","messagePattern":"SR\\.Animation_UnrecognizedHandoffBehavior","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/ContentElement.cs","lineNumber":82,"sourceCode":"            AnimationClock clock,\n            HandoffBehavior handoffBehavior)\n        {\n            ArgumentNullException.ThrowIfNull(dp);\n\n            if (!AnimationStorage.IsPropertyAnimatable(this, dp))\n            {\n                throw new ArgumentException(SR.Format(SR.Animation_DependencyPropertyIsNotAnimatable, dp.Name, this.GetType()), nameof(dp));\n            }\n\n            if (clock != null\n                && !AnimationStorage.IsAnimationValid(dp, clock.Timeline))\n            {\n                throw new ArgumentException(SR.Format(SR.Animation_AnimationTimelineTypeMismatch, clock.Timeline.GetType(), dp.Name, dp.PropertyType), nameof(clock));\n            }\n\n            if (!HandoffBehaviorEnum.IsDefined(handoffBehavior))\n            {\n                throw new ArgumentException(SR.Animation_UnrecognizedHandoffBehavior);\n            }\n\n            if (IsSealed)\n            {\n                throw new InvalidOperationException(SR.Format(SR.IAnimatable_CantAnimateSealedDO, dp, this.GetType()));\n            }\n\n            AnimationStorage.ApplyAnimationClock(this, dp, clock, handoffBehavior);\n        }\n\n        /// <summary>\n        /// Starts an animation for a DependencyProperty. The animation will\n        /// begin when the next frame is rendered.\n        /// </summary>\n        /// <param name=\"dp\">\n        /// The DependencyProperty to animate.\n        /// </param>\n        /// <param name=\"animation\">","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/ContentElement.cs#L64-L100","documentation":"Thrown by ContentElement.ApplyAnimationClock when the handoffBehavior argument is not a defined value of the HandoffBehavior enum (checked via HandoffBehaviorEnum.IsDefined). The library only accepts SnapshotAndReplace and Compose; any other cast or out-of-range value throws ArgumentException.","triggerScenarios":"Passing an undefined HandoffBehavior value, typically from an invalid cast like (HandoffBehavior)99, an uninitialized/und enum variable, or a config-parsed integer outside the enum range.","commonSituations":"Deserializing a handoff behavior from config or XAML-adjacent data with an out-of-range numeric value; refactors that renamed enum members but left stale numeric casts; interop code passing raw ints.","solutions":["Pass only HandoffBehavior.SnapshotAndReplace or HandoffBehavior.Compose.","Validate with Enum.IsDefined(typeof(HandoffBehavior), value) before calling, or use Enum.TryParse.","Replace raw numeric casts of external data with a validated parse.","If the value comes from configuration, fix the config to a valid enum name."],"exampleFix":"// before\nvar behavior = (HandoffBehavior)42;\nel.ApplyAnimationClock(dp, clock, behavior);\n// after\nif (!Enum.IsDefined(typeof(HandoffBehavior), rawValue)) throw new ArgumentOutOfRangeException(nameof(rawValue));\nvar behavior = (HandoffBehavior)rawValue; // now guaranteed valid","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(HandoffBehavior), handoffBehavior))\n    throw new InvalidEnumArgumentException(nameof(handoffBehavior), (int)handoffBehavior, typeof(HandoffBehavior));","typeGuard":"bool IsValidHandoff(HandoffBehavior b) => b is HandoffBehavior.SnapshotAndReplace or HandoffBehavior.Compose;","tryCatchPattern":"try { el.ApplyAnimationClock(dp, clock, behavior); }\ncatch (ArgumentException) { behavior = HandoffBehavior.SnapshotAndReplace; el.ApplyAnimationClock(dp, clock, behavior); }","preventionTips":["Never cast raw ints to HandoffBehavior without Enum.IsDefined validation.","Use Enum.TryParse when reading the value from config or external data.","Prefer strongly-typed enum references over numeric literals in animation code.","Validate enum-typed settings at load time, before any animation calls."],"tags":["wpf","animation","enum","argument-exception"],"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-22T01:17:13.364Z"}