{"record":{"id":"9161e03bfc6bdd7a","repo":"AvaloniaUI/Avalonia","slug":"unknown-playbackbehavior-value-playbackbehavior","errorCode":null,"errorMessage":"Unknown PlaybackBehavior value: {_playbackBehavior}","messagePattern":"Unknown PlaybackBehavior value: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Animation/Animation.cs","lineNumber":313,"sourceCode":"            return (newAnimatorInstances, subscriptions, animatesVisibility);\n        }\n\n        IDisposable IAnimation.Apply(Animatable control, IClock? clock, IObservable<bool> match, Action? onComplete,\n            bool isManuallyStarted)\n            => Apply(control, clock, match, onComplete, isManuallyStarted);\n\n        /// <inheritdoc cref=\"IAnimation.Apply\"/>\n        internal IDisposable Apply(Animatable control, IClock? clock, IObservable<bool> match, Action? onComplete,\n            bool isManuallyStarted = false)\n        {\n            var (animators, subscriptions, animatesVisibility) = InterpretKeyframes(control);\n\n            var shouldPauseOnInvisible = _playbackBehavior switch\n            {\n                PlaybackBehavior.Auto => !(animatesVisibility || isManuallyStarted),\n                PlaybackBehavior.Always => false,\n                PlaybackBehavior.OnlyIfVisible => true,\n                _ => throw new InvalidOperationException($\"Unknown PlaybackBehavior value: {_playbackBehavior}\"),\n            };\n\n            if (animators.Count == 1)\n            {\n                var subscription = animators[0].Apply(this, control, clock, match,\n                    onComplete, shouldPauseOnInvisible);\n\n                if (subscription is not null)\n                {\n                    subscriptions.Add(subscription);\n                }\n            }\n            else\n            {\n                var completionTasks = onComplete != null ? new List<Task>() : null;\n                foreach (IAnimator animator in animators)\n                {\n                    Action? animatorOnComplete = null;","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Animation/Animation.cs#L295-L331","documentation":"Thrown by Animation.Apply when the PlaybackBehavior value does not match any of the known switch arms (Auto, Always, OnlyIfVisible). This is an exhaustive-switch guard: an unexpected/undefined enum value was assigned to the Animation.PlaybackBehavior property.","triggerScenarios":"Assigning PlaybackBehavior an invalid enum value — typically by casting an out-of-range integer to PlaybackBehavior (e.g. (PlaybackBehavior)999), or by referencing a value added in a newer Avalonia version while running against an older runtime that lacks that case.","commonSituations":"Version mismatch between the XAML/code defining the animation and the Avalonia runtime; casting arbitrary ints to the enum; serialization/binding deserializing a numeric value into PlaybackBehavior that falls outside the defined range; reflection-based construction setting an undefined value.","solutions":["Only use the defined PlaybackBehavior members (Auto, Always, OnlyIfVisible) — do not cast arbitrary integers.","Ensure the Avalonia runtime version matches the version that defines the PlaybackBehavior members you reference.","If deserializing PlaybackBehavior, validate the value with Enum.IsDefined before assignment.","Update Avalonia packages consistently across the solution to avoid enum drift."],"exampleFix":"// before\nanim.PlaybackBehavior = (PlaybackBehavior)42; // undefined -> throws\n\n// after\nanim.PlaybackBehavior = Enum.IsDefined(typeof(PlaybackBehavior), raw)\n    ? (PlaybackBehavior)raw\n    : PlaybackBehavior.Auto;","handlingStrategy":"validation","validationCode":"// validate the enum before assigning\nif (!Enum.IsDefined(typeof(PlaybackBehavior), raw))\n    throw new ArgumentOutOfRangeException(nameof(raw));\nanimation.PlaybackBehavior = (PlaybackBehavior)raw;","typeGuard":"static bool IsValidPlaybackBehavior(int v) => Enum.IsDefined(typeof(PlaybackBehavior), v);","tryCatchPattern":null,"preventionTips":["Use only the defined PlaybackBehavior members.","Validate with Enum.IsDefined when deserializing/casting.","Keep Avalonia package versions consistent across the solution.","Avoid casting arbitrary integers to the enum."],"tags":["animation","enum","playback","validation","version-mismatch"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}