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
- Open the Lottie JSON in a validator (lottiefiles.com validator) and confirm Skottie compatibility; remove unsupported effects/expressions and re-export.
- Verify UriSource resolves to the intended file — log sourceUri and stream length before TryCreate to confirm the bytes are the Lottie JSON.
- 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.
- Catch at the AnimatedVisualPlayer level and fall back to a static image or alternate animation.
- 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
- Validate Lottie files with the Skottie parser during build/tests, not only at runtime.
- Pin a SkiaSharp/Skottie version known to support your Lottie schema.
- Keep a canonical set of supported effects when exporting from After Effects.
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
- Failed load the animation
- Failed to load animation: {sourceUri}
- NotImplemented_GetFormattedString
- value
- Unable to find [MapGrid] template part
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/d6e0d02ecf2598bb.
Report an issue: GitHub.