{"record":{"id":"67732a7c472e18b8","repo":"unoplatform/uno","slug":"notimplemented-getformattedstring","errorCode":null,"errorMessage":"NotImplemented_GetFormattedString","messagePattern":"NotImplemented_GetFormattedString","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/AddIns/Uno.UI.Lottie/System.Json/JsonPrimitive.cs","lineNumber":160,"sourceCode":"\t\t\t\t\tstream.Write(bytes, 0, bytes.Length);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tinternal string GetFormattedString()\n\t\t{\n\t\t\tswitch (JsonType)\n\t\t\t{\n\t\t\t\tcase JsonType.String:\n\t\t\t\t\tif (_value is string || _value == null)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn (string)_value;\n\t\t\t\t\t}\n\t\t\t\t\tif (_value is char)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn _value.ToString();\n\t\t\t\t\t}\n\t\t\t\t\tthrow new NotImplementedException(\"NotImplemented_GetFormattedString\");\n\n\t\t\t\tcase JsonType.Number:\n\t\t\t\t\tstring s = _value is float || _value is double ?\n\t\t\t\t\t\t((IFormattable)_value).ToString(\"R\", CultureInfo.InvariantCulture) : // Use \"round-trip\" format\n\t\t\t\t\t\t((IFormattable)_value).ToString(\"G\", CultureInfo.InvariantCulture);\n\t\t\t\t\treturn s == \"NaN\" || s == \"Infinity\" || s == \"-Infinity\" ?\n\t\t\t\t\t\t\"\\\"\" + s + \"\\\"\" :\n\t\t\t\t\t\ts;\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new InvalidOperationException();\n\t\t\t}\n\t\t}\n\t}\n}\n","sourceCodeStart":142,"sourceCodeEnd":176,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/AddIns/Uno.UI.Lottie/System.Json/JsonPrimitive.cs#L142-L176","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — inconsistent state\nvar p = new JsonPrimitive(42);\ntypeof(JsonPrimitive).GetProperty(\"JsonType\")!.SetValue(p, JsonType.String);\np.GetFormattedString(); // throws NotImplemented_GetFormattedString\n\n// after — keep type and value consistent\nvar p = new JsonPrimitive(\"42\"); // JsonType.String with string value\np.GetFormattedString();","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"bool JsonPrimitiveStringConsistent(JsonPrimitive p)\n    => p.JsonType == JsonType.String && (p.Value is string or char || p.Value is null);","tryCatchPattern":null,"preventionTips":["Never mutate JsonPrimitive._value/JsonType via reflection.","Construct JsonPrimitive via typed constructors only.","Use JsonValue.Parse for parsing to keep type/value consistent."],"tags":["system-json","json","lottie","invariant","uno-platform"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}