unoplatform/uno · error · InvalidOperationException

Failed to load animation.

Error message

Failed to load animation.

What it means

Thrown by LottieVisualSource when SkiaSharp.Skottie.Animation.TryCreate returns false, meaning the supplied JSON stream could not be parsed into a Skottie animation. Skottie supports a subset of the Lottie feature set, so well-formed Lottie files using unsupported features will fail to parse here. The error originates inside the OnJsonChanged callback that re-parses the animation data whenever the cached JSON changes.

Source

Thrown at src/AddIns/Uno.UI.Lottie/LottieVisualSource.Skottie.cs:127

							void OnJsonChanged(string updatedJson, string updatedCacheKey)
							{
								try
								{
									var stream = new MemoryStream(Encoding.UTF8.GetBytes(updatedJson));

									if (SkiaSharp.Skottie.Animation.TryCreate(stream, out var animation))
									{
										animation.Seek(0);

										if (this.Log().IsEnabled(LogLevel.Debug))
										{
											this.Log().Debug($"Version: {animation.Version} Duration: {animation.Duration} Fps:{animation.Fps} InPoint: {animation.InPoint} OutPoint: {animation.OutPoint}");
										}
									}
									else
									{
										throw new InvalidOperationException("Failed to load animation.");
									}

									SetAnimation(animation);

									if (_playState != null)
									{
										var (fromProgress, toProgress, looped) = _playState;
										Play(fromProgress, toProgress, looped);
									}
								}
								catch (Exception ex)
								{
									throw new InvalidOperationException("Failed load the animation", ex);
								}
							}
						}
						else
						{

View on GitHub (pinned to 0418340488)

Solutions

  1. Open the Lottie JSON in a validator (lottiefiles.com validator) and confirm Skottie compatibility; remove unsupported effects/expressions and re-export.
  2. Verify UriSource resolves to the intended file — log sourceUri and stream length before TryCreate to confirm the bytes are the Lottie JSON.
  3. Upgrade the SkiaSharp version (and transitively Skottie) referenced by the Uno.UI.Lottie add-in so the parser supports the schema version of your file.
  4. Catch at the AnimatedVisualPlayer level and fall back to a static image or alternate animation.
  5. If the JSON is generated/hot-reloaded, ensure OnJsonChanged receives the complete document (the stream is built from updatedJson via UTF-8 bytes; a partial string yields a parse failure).

Example fix

// before
<Lottie:LottieVisualSource x:Key="Src" UriSource="ms-appx:///Assets/anim.json"/>
<controls:AnimatedVisualPlayer Source="{StaticResource Src}"/>

// after — guard load failure and validate the file parses in Skottie first
try
{
    using var fs = File.OpenRead("Assets/anim.json");
    if (!SkiaSharp.Skottie.Animation.TryCreate(fs, out _))
        ShowFallbackImage();
}
catch (InvalidOperationException) { ShowFallbackImage(); }
Defensive patterns

Strategy: validation

Validate before calling

// Validate the JSON parses with Skottie BEFORE assigning to AnimatedVisualPlayer.Source
using var fs = File.OpenRead(jsonPath);
if (!SkiaSharp.Skottie.Animation.TryCreate(fs, out _))
{
    ShowFallback();
    return;
}
// then assign the source

Type guard

bool IsLottieParseable(Stream json)
    => SkiaSharp.Skottie.Animation.TryCreate(json, out _);

Try / catch

try { player.Source = lottieSource; }
catch (InvalidOperationException ex) when (ex.Message.Contains("Failed to load animation"))
{ ShowFallback(); }

Prevention

When it happens

Trigger: AnimatedVisualPlayer.Source is set to a LottieVisualSource whose UriSource points at a JSON file that Skottie cannot parse: corrupt JSON, a non-Lottie file, or a Lottie that uses bodymovin/Skottie-unsupported effect layers (e.g. certain expressions, gradient strokes, newer schema versions). TryCreate(stream, out animation) returns false and the else-branch throws.

Common situations: Exporting a Lottie from After Effects with unsupported effects enabled; pointing UriSource at the wrong asset (e.g. a .png or the raw .aep); a bodymovin plugin version that emits schema features newer than the SkiaSharp.Skottie version referenced by Uno.UI.Lottie; a JSON file truncated or UTF-8 mangled by a bad ms-appx pack path.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/d6e0d02ecf2598bb. Report an issue: GitHub.