{"record":{"id":"d7a81ae1e9387751","repo":"dotnet/wpf","slug":"sr-animation-unrecognizedhandoffbehavior-visual3d","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/Media3D/Generated/Visual3D.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/Media3D/Generated/Visual3D.cs#L63-L99","documentation":"Visual3D.ApplyAnimationClock validates the handoffBehavior argument against the HandoffBehaviorEnum. If the value is not a defined HandoffBehavior member (SnapshotAndReplace or Compose), an ArgumentException with Animation_UnrecognizedHandoffBehavior is thrown. Only the two enumerated handoff behaviors are accepted when applying an animation clock.","triggerScenarios":"Calling ApplyAnimationClock(dp, clock, handoffBehavior) with an out-of-range enum value — e.g. a raw cast like (HandoffBehavior)99, an uninitialized/unset enum, or a value marshaled from unmanaged/serialized data that was never validated.","commonSituations":"Enum values persisted to XAML/config or received over remoting and cast unchecked; arithmetic or default(int)=0 confusion when composing behavior flags; a HandoffBehavior variable never initialized to a valid member.","solutions":["Pass a valid HandoffBehavior value: HandoffBehavior.SnapshotAndReplace or HandoffBehavior.Compose.","Validate externally supplied enum values with Enum.IsDefined(typeof(HandoffBehavior), value) before passing them in.","If the value comes from serialized config, map unknown values to a documented default explicitly."],"exampleFix":"// before\nvisual.ApplyAnimationClock(dp, clock, (HandoffBehavior)behaviorInt);\n// after\nvar behavior = Enum.IsDefined(typeof(HandoffBehavior), behaviorInt) ? (HandoffBehavior)behaviorInt : HandoffBehavior.SnapshotAndReplace;\nvisual.ApplyAnimationClock(dp, clock, behavior);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(HandoffBehavior), handoffBehavior))\n{\n    handoffBehavior = HandoffBehavior.SnapshotAndReplace; // safe default\n}\nvisual.ApplyAnimationClock(dp, clock, handoffBehavior);","typeGuard":"static bool IsValidHandoffBehavior(HandoffBehavior b) => b is HandoffBehavior.SnapshotAndReplace or HandoffBehavior.Compose;","tryCatchPattern":"try { visual.ApplyAnimationClock(dp, clock, behavior); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"HandoffBehavior\")) { visual.ApplyAnimationClock(dp, clock, HandoffBehavior.SnapshotAndReplace); }","preventionTips":["Never cast ints/bytes to HandoffBehavior without Enum.IsDefined.","Initialize enum fields with an explicit valid member, not default."],"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-21T21:30:21.729Z"}