{"record":{"id":"d6e0d02ecf2598bb","repo":"unoplatform/uno","slug":"failed-to-load-animation","errorCode":null,"errorMessage":"Failed to load animation.","messagePattern":"Failed to load animation\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/AddIns/Uno.UI.Lottie/LottieVisualSource.Skottie.cs","lineNumber":127,"sourceCode":"\n\t\t\t\t\t\t\tvoid OnJsonChanged(string updatedJson, string updatedCacheKey)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttry\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tvar stream = new MemoryStream(Encoding.UTF8.GetBytes(updatedJson));\n\n\t\t\t\t\t\t\t\t\tif (SkiaSharp.Skottie.Animation.TryCreate(stream, out var animation))\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tanimation.Seek(0);\n\n\t\t\t\t\t\t\t\t\t\tif (this.Log().IsEnabled(LogLevel.Debug))\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tthis.Log().Debug($\"Version: {animation.Version} Duration: {animation.Duration} Fps:{animation.Fps} InPoint: {animation.InPoint} OutPoint: {animation.OutPoint}\");\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tthrow new InvalidOperationException(\"Failed to load animation.\");\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\tSetAnimation(animation);\n\n\t\t\t\t\t\t\t\t\tif (_playState != null)\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tvar (fromProgress, toProgress, looped) = _playState;\n\t\t\t\t\t\t\t\t\t\tPlay(fromProgress, toProgress, looped);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcatch (Exception ex)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tthrow new InvalidOperationException(\"Failed load the animation\", ex);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/AddIns/Uno.UI.Lottie/LottieVisualSource.Skottie.cs#L109-L145","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\n<Lottie:LottieVisualSource x:Key=\"Src\" UriSource=\"ms-appx:///Assets/anim.json\"/>\n<controls:AnimatedVisualPlayer Source=\"{StaticResource Src}\"/>\n\n// after — guard load failure and validate the file parses in Skottie first\ntry\n{\n    using var fs = File.OpenRead(\"Assets/anim.json\");\n    if (!SkiaSharp.Skottie.Animation.TryCreate(fs, out _))\n        ShowFallbackImage();\n}\ncatch (InvalidOperationException) { ShowFallbackImage(); }","handlingStrategy":"validation","validationCode":"// Validate the JSON parses with Skottie BEFORE assigning to AnimatedVisualPlayer.Source\nusing var fs = File.OpenRead(jsonPath);\nif (!SkiaSharp.Skottie.Animation.TryCreate(fs, out _))\n{\n    ShowFallback();\n    return;\n}\n// then assign the source","typeGuard":"bool IsLottieParseable(Stream json)\n    => SkiaSharp.Skottie.Animation.TryCreate(json, out _);","tryCatchPattern":"try { player.Source = lottieSource; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Failed to load animation\"))\n{ ShowFallback(); }","preventionTips":["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."],"tags":["lottie","skottie","animation","parsing","uno-platform"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}