{"record":{"id":"8cd91bc1f48f82b5","repo":"OrchardCMS/OrchardCore","slug":"cannot-parse-number","errorCode":null,"errorMessage":"Cannot parse number.","messagePattern":"Cannot parse number\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Abstractions/Json/Nodes/JValue.cs","lineNumber":93,"sourceCode":"                    return longValue;\n                }\n\n                if (jsonValue.TryGetValue<decimal>(out var decimalValue))\n                {\n                    return decimalValue;\n                }\n\n                if (jsonElement.TryGetBigInteger(out var bigInteger))\n                {\n                    return bigInteger;\n                }\n\n                if (jsonValue.TryGetValue<double>(out var doubleValue))\n                {\n                    return doubleValue;\n                }\n\n                throw new JsonException(\"Cannot parse number.\");\n\n            default:\n                throw new JsonException(string.Format(\"Unknown token type {0}\", jsonElement.ValueKind));\n        }\n    }\n}\n","sourceCodeStart":75,"sourceCodeEnd":100,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Abstractions/Json/Nodes/JValue.cs#L75-L100","documentation":"This JsonException is thrown by JValue.GetObjectValue when the underlying JSON token is a Number but it cannot be materialized as any supported numeric type — the integer conversions fail and TryGetValue<double> also fails. Effectively the number is malformed or outside all supported ranges.","triggerScenarios":"Calling GetObjectValue() on a JValue whose JsonElement ValueKind is Number but whose text cannot be parsed to double (e.g. extremely large exponents, malformed number text produced by custom writers).","commonSituations":"JSON documents with hand-edited or corrupted number literals; numbers exceeding double range (e.g. 1e400); interop with producers emitting non-standard numeric syntax.","solutions":["Fix the source JSON so numbers are valid and within double range","Pre-validate the number text before parsing the document","Catch JsonException around GetObjectValue and treat as parse failure","Use a JsonElement TryGet pattern (TryGetInt64/TryGetDouble) to inspect the token yourself"],"exampleFix":"// before\nvar v = jValue.GetObjectValue();\n// after\ndouble v;\ntry { v = Convert.ToDouble(jValue.GetObjectValue()); }\ncatch (JsonException) { v = 0; }","handlingStrategy":"try-catch","validationCode":"if (jsonElement.ValueKind != JsonValueKind.Number)\n    throw new InvalidOperationException(\"Token is not a number\");\nif (!jsonElement.TryGetDouble(out _))\n    throw new InvalidOperationException(\"Number cannot be parsed as double\");","typeGuard":null,"tryCatchPattern":"object? v;\ntry { v = jValue.GetObjectValue(); }\ncatch (JsonException ex) { /* log ex, treat as bad number */ v = null; }","preventionTips":["Validate number literals in externally produced JSON","Reject numbers outside double range (e.g. 1e400) at ingestion","Keep JsonElement parsing to the System.Text.Json reader, not hand-built JSON","Wrap GetObjectValue in try/catch at ingestion boundaries"],"tags":["json","number-parsing","jsonexception","out-of-range"],"backgroundTag":"json-parse-error","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}