{"record":{"id":"099f65509c6418c4","repo":"XINCGer/Unity3DTraining","slug":"value-out-of-range-text","errorCode":null,"errorMessage":"Value out of range: {text}","messagePattern":"Value out of range: (.+?)","errorType":"exception","errorClass":"InvalidProtocolBufferException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":764,"sourceCode":"            }\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            {\n                throw new InvalidProtocolBufferException(\"Invalid numeric value: \" + text);\n            }\n        }\n","sourceCodeStart":746,"sourceCodeEnd":782,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L746-L782","documentation":"ParseNumericString catches OverflowException from the underlying type parser (e.g. int.Parse on a value beyond int.MaxValue) and rethrows it as InvalidProtocolBufferException('Value out of range: ' + text). This means the JSON number is grammatically valid but cannot fit the declared proto field type (e.g. 3000000000 for int32, or a double too large for a float field).","triggerScenarios":"JsonParser.Parse<T> where a numeric field receives a value outside its type's range: >2^31-1 for int32, >2^63-1 for int64, magnitudes beyond float range for float fields, or negative values for unsigned-typed fields.","commonSituations":"Server using 64-bit IDs sent into an int32 field; timestamp-like millisecond values exceeding int32; language-agnostic producers assuming 'int' means 64-bit; float fields given double-precision extremes.","solutions":["Change the proto field to a wider type (int64/uint64 or double) and regenerate the C# classes","Clamp or validate the value client-side against the target type's MinValue/MaxValue before serializing/parsing","For big values that must stay int32-typed per an existing schema, transmit them as strings (int64-as-string JSON mapping)","Use unsigned types (uint32/uint64) if values only overflow because they were meant to be non-negative"],"exampleFix":"// before\n// proto: int32 id = 1;  json: {\"id\": 3000000000} -> overflow\n// after\n// proto: int64 id = 1;  regenerate stubs, then:\nvar msg = JsonParser.Default.Parse<Message>(\"{\\\"id\\\": 3000000000}\");","handlingStrategy":"validation","validationCode":"bool FitsType(long v, string protoType) => protoType switch {\n    \"int32\"  => v >= int.MinValue && v <= int.MaxValue,\n    \"uint32\" => v >= 0 && v <= uint.MaxValue,\n    \"int64\"  => true,\n    _ => true\n};\n// check bounds before serializing into JSON","typeGuard":null,"tryCatchPattern":"try { return JsonParser.Default.Parse<T>(json); }\ncatch (InvalidProtocolBufferException ex) when (ex.Message.StartsWith(\"Value out of range\")) {\n    logger.LogWarning(ex, \"Numeric value exceeds field type range\");\n    return null;\n}","preventionTips":["Prefer int64/double in protos when values may grow (IDs, timestamps in ms)","Clamp or validate against the target type's MinValue/MaxValue before sending","Use int64-as-string JSON mapping for huge values against fixed schemas","Document field ranges in the .proto comments"],"tags":["protobuf","json","numeric","overflow"],"backgroundTag":"value-out-of-range","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"}