{"record":{"id":"4ed8a67426dc7a9c","repo":"XINCGer/Unity3DTraining","slug":"invalid-numeric-value","errorCode":null,"errorMessage":"Invalid numeric value: ","messagePattern":"Invalid numeric value: ","errorType":"validation","errorClass":"InvalidProtocolBufferException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":738,"sourceCode":"                default:\n                    throw new InvalidProtocolBufferException(\"Unsupported conversion from JSON string for field type \" + field.FieldType);\n            }\n        }\n\n        /// <summary>\n        /// Creates a new instance of the message type for the given field.\n        /// </summary>\n        private static IMessage NewMessageForField(FieldDescriptor field)\n        {\n            return field.MessageType.Parser.CreateTemplate();\n        }\n\n        private static T ParseNumericString<T>(string text, Func<string, NumberStyles, IFormatProvider, T> parser)\n        {\n            // Can't prohibit this with NumberStyles.\n            if (text.StartsWith(\"+\"))\n            {\n                throw new InvalidProtocolBufferException(\"Invalid numeric value: \" + text);\n            }\n            if (text.StartsWith(\"0\") && text.Length > 1)\n            {\n                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);","sourceCodeStart":720,"sourceCodeEnd":756,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L720-L756","documentation":"ParseNumericString validates textual numeric tokens before delegating to int/long/double parsers. The protobuf JSON spec forbids a leading '+' on numbers, so any text starting with '+' is rejected with InvalidProtocolBufferException. JSON numbers must follow the strict JSON grammar; '+5' is invalid JSON.","triggerScenarios":"Calling JsonParser.Parse<T> with numeric fields whose values are written with an explicit plus sign, e.g. {\"score\": \"+10\"} where a string-form numeric is parsed, or code that formats numbers with a custom format string including a sign specifier ('+0;-0;0').","commonSituations":"Config files hand-edited with '+value' notation; log/telemetry strings that carry explicit signs; sprintf-style formatting with '+' flag reused to build JSON; pasting values from spreadsheets.","solutions":["Remove the leading '+' from the numeric string (an unsigned positive number needs no sign)","Fix the formatter producing the string (e.g. drop the '+' section in a .NET format string)","Parse with double/int.Parse on the cleaned value before embedding it into JSON","Pre-strip or reject '+'-prefixed numerics in your JSON preprocessing step"],"exampleFix":"// before\nstring json = \"{\\\"score\\\": \\\"+10\\\"}\"; // leading '+' rejected\n// after\nstring json = \"{\\\"score\\\": 10}\";","handlingStrategy":"validation","validationCode":"static readonly System.Text.RegularExpressions.Regex JsonNumber =\n    new System.Text.RegularExpressions.Regex(@\"^-?(0|[1-9]\\d*)(\\.\\d+)?([eE][+-]?\\d+)?$\");\nbool IsValidJsonNumber(string text) => JsonNumber.IsMatch(text);","typeGuard":null,"tryCatchPattern":"try { return JsonParser.Default.Parse<T>(json); }\ncatch (InvalidProtocolBufferException ex) when (ex.Message.StartsWith(\"Invalid numeric value\")) {\n    logger.LogWarning(ex, \"Malformed JSON number\");\n    return null;\n}","preventionTips":["Use invariant-culture ToString for numbers, never format strings with '+' sections","Validate payloads with a strict JSON parser before protobuf parsing","Ban sign-prefixed numerics in upstream producers"],"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"}