{"record":{"id":"75f5ed68d876487b","repo":"XINCGer/Unity3DTraining","slug":"invalid-numeric-value-text","errorCode":null,"errorMessage":"Invalid numeric value: {text}","messagePattern":"Invalid numeric value: (.+?)","errorType":"exception","errorClass":"InvalidProtocolBufferException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":779,"sourceCode":"            }\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            {\n                throw new InvalidProtocolBufferException(\"Invalid numeric value: \" + text);\n            }\n        }\n\n        private static void MergeTimestamp(IMessage message, JsonToken token)\n        {\n            if (token.Type != JsonToken.TokenType.StringValue)\n            {\n                throw new InvalidProtocolBufferException(\"Expected string value for Timestamp\");\n            }\n            var match = TimestampRegex.Match(token.StringValue);\n            if (!match.Success)\n            {\n                throw new InvalidProtocolBufferException(\"Invalid Timestamp value: \" + token.StringValue);\n            }\n            var dateTime = match.Groups[\"datetime\"].Value;\n            var subseconds = match.Groups[\"subseconds\"].Value;\n            var offset = match.Groups[\"offset\"].Value;\n","sourceCodeStart":761,"sourceCodeEnd":797,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L761-L797","documentation":"When a JSON string is parsed into a float/double field, ParseSingleStringValue checks whether the parsed value ended up as Infinity, -Infinity or NaN. The protobuf JSON mapping only permits the exact tokens 'Infinity', '-Infinity' and 'NaN' to denote these values; if the CLR parser produced a special value from some other text (a side effect of lenient parsing, e.g. case variants or whitespace handling), ValidateInfinityAndNan throws InvalidProtocolBufferException('Invalid numeric value: ' + text).","triggerScenarios":"JsonParser.Parse<T> on float/double fields with strings like 'infinity', '+Infinity', ' NaN ', or 'Inf' — tokens the CLR parser may accept leniently but that are not the spec-mandated spellings.","commonSituations":"JSON generated by non-.NET serializers using different infinity spellings; data round-tripped through logs or metrics systems that lowercase tokens; hand-written JSON with sign-prefixed Infinity.","solutions":["Use the exact tokens 'Infinity', '-Infinity' or 'NaN' as unquoted-per-spec JSON strings for special float values","Normalize incoming tokens (trim, fix case, strip '+') before parsing","Replace non-finite values with valid finite numbers or omit the field if special values are not required","Validate float tokens against the three allowed special strings before calling the parser"],"exampleFix":"// before\nparser.Parse<Point>(\"{\\\"x\\\": \\\"infinity\\\"}\"); // wrong spelling\n// after\nparser.Parse<Point>(\"{\\\"x\\\": \\\"Infinity\\\"}\");","handlingStrategy":"validation","validationCode":"bool IsValidSpecialFloat(string text) =>\n    text == \"Infinity\" || text == \"-Infinity\" || text == \"NaN\" ||\n    double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var d) && !double.IsInfinity(d) && !double.IsNaN(d);","typeGuard":null,"tryCatchPattern":"try { return JsonParser.Default.Parse<T>(json); }\ncatch (InvalidProtocolBufferException ex) when (ex.Message.StartsWith(\"Invalid numeric value\")) {\n    logger.LogWarning(ex, \"Non-spec float token (Infinity/NaN spelling)\");\n    return null;\n}","preventionTips":["Only emit exactly 'Infinity', '-Infinity', 'NaN' for special floats","Normalize case and strip '+'/whitespace from incoming float tokens","Prefer omitting fields over encoding NaN/Infinity when consumers don't need them"],"tags":["protobuf","json","float","nan","infinity"],"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"}