{"record":{"id":"91b87f3e58fc4235","repo":"dotnet/wpf","slug":"animation-unrecognizedhandoffbehavior","errorCode":"Animation_UnrecognizedHandoffBehavior","errorMessage":"SR.Animation_UnrecognizedHandoffBehavior (Animation_UnrecognizedHandoffBehavior)","messagePattern":"SR\\.Animation_UnrecognizedHandoffBehavior \\(Animation_UnrecognizedHandoffBehavior\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Animatable.cs","lineNumber":81,"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":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Animatable.cs#L63-L99","documentation":"The handoffBehavior argument to ApplyAnimationClock is not a defined AnimationClock value (only SnapshotAndReplace and Compose are valid). HandoffBehaviorEnum.IsDefined fails and an ArgumentException is thrown. The enum dictates how a new animation clock combines with any existing animation on the property.","triggerScenarios":"Passing an out-of-range integer cast to HandoffBehavior (e.g. (HandoffBehavior)42) or an uninitialized/defaulted enum value that is not one of the two defined members.","commonSituations":"Storing HandoffBehavior in config/database as an int and casting back; deserializing invalid enum values from XAML-generated or persisted state; typos in bindings producing default(HandoffBehavior)=0 is valid, so this usually appears only with explicit bad casts.","solutions":["Pass HandoffBehavior.SnapshotAndReplace or HandoffBehavior.Compose explicitly.","Validate any int before casting: Enum.IsDefined(typeof(HandoffBehavior), value).","Fix serialization code to round-trip enum names (Enum.ToString/Enum.Parse) instead of raw integers."],"exampleFix":"// before\nvar behavior = (HandoffBehavior)storedInt; // may be invalid\nanim.ApplyAnimationClock(dp, clock, behavior);\n// after\nif (!Enum.IsDefined(typeof(HandoffBehavior), storedInt)) throw new InvalidDataException(...);\nanim.ApplyAnimationClock(dp, clock, (HandoffBehavior)storedInt);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(HandoffBehavior), handoffBehavior))\n    throw new InvalidEnumArgumentException(nameof(handoffBehavior), (int)handoffBehavior, typeof(HandoffBehavior));","typeGuard":"static bool IsValidHandoff(HandoffBehavior h) =>\n    h == HandoffBehavior.SnapshotAndReplace || h == HandoffBehavior.Compose;","tryCatchPattern":"try { target.ApplyAnimationClock(dp, clock, behavior); }\ncatch (ArgumentException) { /* fall back to SnapshotAndReplace */ }","preventionTips":["Never cast raw ints to HandoffBehavior without Enum.IsDefined.","Serialize enums by name.","Expose only the two valid values in your API surface."],"tags":["wpf","animation","enum","invalid-argument"],"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"}