dotnet/wpf · error · InvalidOperationException
SR.IAnimatable_CantAnimateSealedDO (formatted with dp and…
Error message
SR.IAnimatable_CantAnimateSealedDO (formatted with dp and this.GetType())
What it means
UIElement.BeginAnimation throws InvalidOperationException(SR.IAnimatable_CantAnimateSealedDO, formatted with the DP and this.GetType()) when the element IsSealed. Animation mutates the dependency-object's state, which is forbidden on sealed/frozen DependencyObjects, so the library throws before starting the animation.
Solutions
- Clone the freezable (Clone()/CloneCurrentValue()) so an unfrozen instance can be animated, then assign it back.
- Avoid Freeze() on objects that will be animated.
- Animate via the owning element instead (e.g. animate element.RenderTransform's properties on an unfrozen transform).
Example fix
// before translateTransform.Freeze(); translateTransform.BeginAnimation(TranslateTransform.XProperty, anim); // after var t = translateTransform.Clone(); // keep unfrozen t.BeginAnimation(TranslateTransform.XProperty, anim); element.RenderTransform = t;
Defensive patterns
Strategy: type-guard
Validate before calling
if (target is Freezable fr && fr.IsFrozen) { target = fr.Clone(); } // animate unfrozen instance Type guard
bool CanBeginAnimation(DependencyObject o) => o is not Freezable f || !f.IsFrozen;
Try / catch
try { target.BeginAnimation(dp, anim, hb); }
catch (InvalidOperationException) { var clone = ((Freezable)target).Clone(); clone.BeginAnimation(dp, anim, hb); owner = clone; } Prevention
- Skip Freeze() on objects that will be animated.
- Check IsFrozen before animation calls.
- Animate parent elements rather than frozen shared resources.
When it happens
Trigger: Calling BeginAnimation on a frozen Freezable (Brush, Pen, Geometry, Transform) or otherwise sealed DependencyObject; animating a shared frozen resource instance.
Common situations: Styles/resources that froze a brush, then code tries to animate it; calling Freeze() earlier in the object lifetime; animating a frozen Transform used in a RenderTransform that was frozen for performance.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- SR.Format(SR.IAnimatable_CantAnimateSealedDO, dp…
- IAnimatable_CantAnimateSealedDO
- SR.Format(SR.Storyboard_ImmutableTargetNotSupported…
- SR.IAnimatable_CantAnimateSealedDO
- SR.IAnimatable_CantAnimateSealedDO
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1242e5660da1d15e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/UIElement.cs:152
if (!AnimationStorage.IsPropertyAnimatable(this, dp))
{
throw new ArgumentException(SR.Format(SR.Animation_DependencyPropertyIsNotAnimatable, dp.Name, this.GetType()), nameof(dp));
}
if (animation != null
&& !AnimationStorage.IsAnimationValid(dp, animation))
{
throw new ArgumentException(SR.Format(SR.Animation_AnimationTimelineTypeMismatch, animation.GetType(), dp.Name, dp.PropertyType), nameof(animation));
}
if (!HandoffBehaviorEnum.IsDefined(handoffBehavior))
{
throw new ArgumentException(SR.Animation_UnrecognizedHandoffBehavior);
}
if (IsSealed)
{
throw new InvalidOperationException(SR.Format(SR.IAnimatable_CantAnimateSealedDO, dp, this.GetType()));
}
AnimationStorage.BeginAnimation(this, dp, animation, handoffBehavior);
}
/// <summary>
/// Returns true if any properties on this DependencyObject have a
/// persistent animation or the object has one or more clocks associated
/// with any of its properties.
/// </summary>
public bool HasAnimatedProperties
{
get
{
VerifyAccess();
return IAnimatable_HasAnimatedProperties;
}View on GitHub (pinned to 81131a70a4)