{"record":{"id":"d0e74b103aa06a0d","repo":"dotnet/wpf","slug":"sr-animation-invalid-defaultvalue-rectanimation","errorCode":null,"errorMessage":"SR.Animation_Invalid_DefaultValue","messagePattern":"SR\\.Animation_Invalid_DefaultValue","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/RectAnimation.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.IsValidAnimationValueRect(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.IsValidAnimationValueRect(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/RectAnimation.cs#L295-L331","documentation":"RectAnimation.GetCurrentValueCore throws this InvalidOperationException when the default origin value supplied by the animation system is not a valid animation value for type Rect (checked via AnimatedTypeHelpers.IsValidAnimationValueRect). WPF requires origin/destination fallback values to be valid, finite Rect values; an invalid (e.g. empty or non-animatable) value cannot seed the interpolation. The message names the offending property ('origin') and its value.","triggerScenarios":"Calling GetCurrentValueCore (directly or via the animation clock) with validateOrigin=true and a defaultOriginValue that fails AnimatedTypeHelpers.IsValidAnimationValueRect — e.g. Rect.Empty or an uninitialized Rect used as the base value of the animated property.","commonSituations":"Animating a Rect-typed dependency property whose current value is Rect.Empty (e.g. RectangleGeometry.Rect never initialized), or hand-rolled animation code passing an empty/default Rect as the origin.","solutions":["Initialize the animated property to a valid, non-empty Rect (e.g. new Rect(0,0,100,100)) before the animation runs","Provide explicit From/To values on the RectAnimation so default origin/destination values are not needed","Wrap the animation start in try/catch for InvalidOperationException and fall back to a valid base value"],"exampleFix":"// before\nrectAnimation.From = null; // relies on base value which is Rect.Empty\n// after\nrectAnimation.From = new Rect(0, 0, 100, 100); // valid origin, no default needed","handlingStrategy":"validation","validationCode":"if (!rect.IsValid || rect == Rect.Empty) { /* fix or set a valid base value before animating */ }","typeGuard":"bool IsValidAnimationOrigin(Rect r) => r != Rect.Empty && r.Width >= 0 && r.Height >= 0;","tryCatchPattern":"try { target.BeginAnimation(RectProperty, anim); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"origin\")) { anim.From = new Rect(0,0,1,1); target.BeginAnimation(RectProperty, anim); }","preventionTips":["Always initialize Rect-typed properties to a non-empty Rect before animating","Prefer explicit From/To on animations over relying on base values","Check Rect.IsEmpty before BeginAnimation"],"tags":["wpf","animation","invalid-value"],"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"}