{"record":{"id":"a0e30776b96bfc1e","repo":"dotnet/wpf","slug":"animation-invalid-defaultvalue","errorCode":"Animation_Invalid_DefaultValue","errorMessage":"SR.Animation_Invalid_DefaultValue (Animation_Invalid_DefaultValue)","messagePattern":"SR\\.Animation_Invalid_DefaultValue \\(Animation_Invalid_DefaultValue\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/ByteAnimation.cs","lineNumber":313,"sourceCode":"                    if (IsAdditive)\n                    {\n                        foundation = defaultOriginValue;\n                        validateOrigin = true;\n                    }\n\n                    break;\n\n                default:\n\n                    Debug.Fail(\"Unknown animation type.\");\n\n                    break;\n            }\n\n            if (validateOrigin \n                && !AnimatedTypeHelpers.IsValidAnimationValueByte(defaultOriginValue))\n            {\n                throw new InvalidOperationException(\n                    SR.Format(\n                        SR.Animation_Invalid_DefaultValue,\n                        this.GetType(),\n                        \"origin\",\n                        defaultOriginValue.ToString(CultureInfo.InvariantCulture)));\n            }\n\n            if (validateDestination \n                && !AnimatedTypeHelpers.IsValidAnimationValueByte(defaultDestinationValue))\n            {\n                throw new InvalidOperationException(\n                    SR.Format(\n                        SR.Animation_Invalid_DefaultValue,\n                        this.GetType(),\n                        \"destination\",\n                        defaultDestinationValue.ToString(CultureInfo.InvariantCulture)));\n            }\n","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/ByteAnimation.cs#L295-L331","documentation":"ByteAnimation.GetCurrentValueCore throws InvalidOperationException when the animation must supply a default origin value (validateOrigin is true and defaultOriginValue was not provided) but that value is not a valid animation value for Byte (per AnimatedTypeHelpers.IsValidAnimationValueByte). WPF refuses to guess an origin for the animated Byte because no valid starting value exists.","triggerScenarios":"Calling GetCurrentValue/GetCurrentValueCore with defaultOriginValue==null (or an invalid default) while the animation has no From value set and no prior/current value to use as origin.","commonSituations":"Animating a byte property where neither From nor a base value is available — e.g. animation targeting a property that has never been set, or manually invoking the animation API without origin/destination values.","solutions":["Set the From property on the ByteAnimation so an explicit origin exists","Pass a valid byte defaultOriginValue when calling GetCurrentValueCore","Ensure the target property has a valid base value before the animation runs"],"exampleFix":"// before\nvar anim = new ByteAnimation { To = 100 };\nanimation.BeginAnimation(byteProperty, anim, null); // no origin value\n// after\nvar anim = new ByteAnimation { From = 0, To = 100 };","handlingStrategy":"validation","validationCode":"if (!anim.From.HasValue && (defaultOriginValue == null || !IsValidByte(defaultOriginValue)))\n    anim.From = 0; // supply explicit origin before evaluating","typeGuard":"static bool HasValidOrigin(ByteAnimation a) => a.From.HasValue;","tryCatchPattern":"try { value = anim.GetCurrentValue(baseValue, null, clock, defaultClock); }\ncatch (InvalidOperationException) { /* missing/invalid origin: set From or base value */ }","preventionTips":["Always set From on From/To/By animations, or ensure the target property has a base value","Do not call GetCurrentValueCore directly with null default values unless another source exists","Initialize animated byte properties before starting the animation"],"tags":["wpf","animation","invalid-operation","byte-animation"],"backgroundTag":"invalid-argument-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"}