{"record":{"id":"9a6a3d648f2b756b","repo":"XINCGer/Unity3DTraining","slug":"invalid-numeric-value-for-type","errorCode":null,"errorMessage":"Invalid numeric value for type: ","messagePattern":"Invalid numeric value for type: ","errorType":"validation","errorClass":"InvalidProtocolBufferException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":760,"sourceCode":"                if (text[1] >= '0' && text[1] <= '9')\n                {\n                    throw new InvalidProtocolBufferException(\"Invalid numeric value: \" + text);\n                }\n            }\n            else if (text.StartsWith(\"-0\") && text.Length > 2)\n            {\n                if (text[2] >= '0' && text[2] <= '9')\n                {\n                    throw new InvalidProtocolBufferException(\"Invalid numeric value: \" + text);\n                }\n            }\n            try\n            {\n                return parser(text, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, CultureInfo.InvariantCulture);\n            }\n            catch (FormatException)\n            {\n                throw new InvalidProtocolBufferException(\"Invalid numeric value for type: \" + text);\n            }\n            catch (OverflowException)\n            {\n                throw new InvalidProtocolBufferException(\"Value out of range: \" + text);\n            }\n        }\n\n        /// <summary>\n        /// Checks that any infinite/NaN values originated from the correct text.\n        /// This corrects the lenient whitespace handling of double.Parse/float.Parse, as well as the\n        /// way that Mono parses out-of-range values as infinity.\n        /// </summary>\n        private static void ValidateInfinityAndNan(string text, bool isPositiveInfinity, bool isNegativeInfinity, bool isNaN)\n        {\n            if ((isPositiveInfinity && text != \"Infinity\") ||\n                (isNegativeInfinity && text != \"-Infinity\") ||\n                (isNaN && text != \"NaN\"))\n            {","sourceCodeStart":742,"sourceCodeEnd":778,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L742-L778","documentation":"After passing the grammar checks, ParseNumericString invokes the actual parser (int.Parse/long.Parse/double.Parse via delegate) with invariant culture. A FormatException means the text, while superficially numeric-looking, is not parseable as the target CLR type (e.g. embedded whitespace, multiple decimal points, trailing garbage). The library rethrows it as InvalidProtocolBufferException('Invalid numeric value for type: ' + text).","triggerScenarios":"JsonParser.Parse<T> with numeric tokens like '1 000', '1.2.3', '0x1F', '1_000', or a double-formatted token for an int-typed field where the parser delegate expects an integer form.","commonSituations":"Numbers scraped from UIs with thousand separators or spaces; hex or underscore literals copied from source code; locale-formatted strings (comma decimal separator) leaking into JSON; template concatenation mistakes.","solutions":["Validate/normalize the numeric string before embedding it in JSON (strip separators, use '.' as decimal point)","Use CultureInfo.InvariantCulture when converting numbers to strings for JSON","Parse the value yourself first (int.TryParse/InvariantCulture) and serialize the typed value, not the raw string","Check which proto field type the token targets and match its expected textual form (integer vs decimal vs exponent)"],"exampleFix":"// before\nstring json = \"{\\\"amount\\\": \" + amount.ToString(\"N2\") + \"}\"; // \"1,234.50\"\n// after\nstring json = \"{\\\"amount\\\": \" + amount.ToString(CultureInfo.InvariantCulture) + \"}\"; // 1234.5","handlingStrategy":"validation","validationCode":"bool IsCleanNumber(string text) =>\n    double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out _);","typeGuard":null,"tryCatchPattern":"try { return JsonParser.Default.Parse<T>(json); }\ncatch (InvalidProtocolBufferException ex) when (ex.Message.StartsWith(\"Invalid numeric value for type\")) {\n    logger.LogWarning(ex, \"Non-parseable numeric token\");\n    return null;\n}","preventionTips":["Always convert numbers to strings with CultureInfo.InvariantCulture","Strip locale separators (spaces, thousands separators) before embedding in JSON","Parse-then-serialize typed values instead of concatenating raw strings"],"tags":["protobuf","json","numeric","format"],"backgroundTag":"json-parse-error","analyzedSha":"016f98412ea5e11756b286736f479b66ab6216d5","analyzedAt":"2026-09-12T01:08:58.711Z","contentChangedAt":"2026-09-12T01:08:58.711Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}