unoplatform/uno · error · NotImplementedException
NotImplemented_GetFormattedString
Error message
NotImplemented_GetFormattedString
What it means
Thrown by System.Json.JsonPrimitive.GetFormattedString when JsonType is String but the stored _value is neither a string, null, nor char — an internal invariant violation of the JsonPrimitive. This is a vendored copy of the .NET corefx System.Json library shipped inside Uno.UI.Lottie. It indicates a JsonPrimitive was constructed in an inconsistent state (a non-string/cl type stored under JsonType.String).
Source
Thrown at src/AddIns/Uno.UI.Lottie/System.Json/JsonPrimitive.cs:160
stream.Write(bytes, 0, bytes.Length);
break;
}
}
internal string GetFormattedString()
{
switch (JsonType)
{
case JsonType.String:
if (_value is string || _value == null)
{
return (string)_value;
}
if (_value is char)
{
return _value.ToString();
}
throw new NotImplementedException("NotImplemented_GetFormattedString");
case JsonType.Number:
string s = _value is float || _value is double ?
((IFormattable)_value).ToString("R", CultureInfo.InvariantCulture) : // Use "round-trip" format
((IFormattable)_value).ToString("G", CultureInfo.InvariantCulture);
return s == "NaN" || s == "Infinity" || s == "-Infinity" ?
"\"" + s + "\"" :
s;
default:
throw new InvalidOperationException();
}
}
}
}
View on GitHub (pinned to 0418340488)
Solutions
- Do not construct JsonPrimitive with a type that conflicts with JsonType; use the typed constructors (JsonPrimitive(string), JsonPrimitive(char)).
- If consuming third-party JSON, parse with JsonValue.Parse which sets JsonType consistently rather than hand-building primitives.
- If you hit this in the Lottie pipeline, capture the JSON string being parsed and validate it externally — the exception implies an internal state bug, so file it against Uno.UI.Lottie with a repro.
- Avoid mutating JsonPrimitive._value via reflection/serialization binders.
Example fix
// before — inconsistent state
var p = new JsonPrimitive(42);
typeof(JsonPrimitive).GetProperty("JsonType")!.SetValue(p, JsonType.String);
p.GetFormattedString(); // throws NotImplemented_GetFormattedString
// after — keep type and value consistent
var p = new JsonPrimitive("42"); // JsonType.String with string value
p.GetFormattedString(); Defensive patterns
Strategy: type-guard
Type guard
bool JsonPrimitiveStringConsistent(JsonPrimitive p)
=> p.JsonType == JsonType.String && (p.Value is string or char || p.Value is null); Prevention
- Never mutate JsonPrimitive._value/JsonType via reflection.
- Construct JsonPrimitive via typed constructors only.
- Use JsonValue.Parse for parsing to keep type/value consistent.
When it happens
Trigger: A JsonPrimitive instance whose JsonType was set to String but _value holds an incompatible CLR type (e.g. via reflection or a deserialization edge case), then GetFormattedString() is invoked during JSON serialization of a Lottie payload.
Common situations: Manipulating System.Json primitives through reflection or interop; a corrupted/hand-built Lottie JSON object tree where a node's type and value disagree; extremely rare in normal Lottie playback. Almost always a sign of programmatic misuse rather than a bad input file.
Related errors
- value
- Failed to load animation.
- Failed load the animation
- Failed to load animation: {sourceUri}
- Unable to find [MapGrid] template part
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/67732a7c472e18b8.
Report an issue: GitHub.