XINCGer/Unity3DTraining · error · InvalidProtocolBufferException

Value not an integer:

Error message

Value not an integer: 

What it means

CheckInteger is a validation helper used when parsing a JSON number into an enum field. It rejects any double that is infinity, NaN, or has a fractional part, since enums in proto3 JSON must be plain integers. The faulting input is the numeric JSON token being converted, echoed in the message.

Solutions

  1. Correct the JSON payload so enum fields carry integer values.
  2. Wrap JsonParser.Parse in try/catch for InvalidProtocolBufferException and return a descriptive 400-style error to the sender.
  3. Validate numeric fields (finite, integral) before serialization on the producing side.

Example fix

Fix the JSON so the enum is a whole number, e.g. "status": 2 instead of "status": 2.5; on the client, cast the enum value to int before emitting JSON.
Defensive patterns

Strategy: validation

Validate before calling

// Reject non-finite or fractional values before serializing integer fields
static void EnsureInteger(object value)
{
    double d = Convert.ToDouble(value);
    if (double.IsNaN(d) || double.IsInfinity(d) || d != Math.Floor(d))
        throw new FormatException($"Value {d} is not an integer");
}

Type guard

static bool IsWholeNumber(double v) => !double.IsNaN(v) && !double.IsInfinity(v) && v == Math.Floor(v);

Try / catch

try
{
    var msg = parser.Parse<T>(json);
}
catch (InvalidProtocolBufferException ex) when (ex.Message.StartsWith("Value not an integer:"))
{
    // round and retry, or surface a data-quality error
}

Prevention

When it happens

Trigger: Parsing a JSON document where an enum field is given a JSON number that is not a whole number (e.g. 1.5) or a special value like Infinity/NaN.

Common situations: Malformed or hand-written JSON payload sent to a protobuf parser; a client serializing an enum with a computed float value; servers receiving rounding artifacts or NaN from upstream data.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of XINCGer/Unity3DTraining@016f98412e (2026-09-12). Data as JSON: /api/errors/f98204d82344a83b. Report an issue: GitHub.

Appendix: source

Thrown at NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs:667

        private static void CheckInteger(double value)
        {
            if (double.IsInfinity(value) || double.IsNaN(value))
            {
                throw new InvalidProtocolBufferException("Value not an integer: " + value);
            }
            if (value != Math.Floor(value))
            {
                throw new InvalidProtocolBufferException("Value not an integer: " + value);
            }
        }

View on GitHub (pinned to 016f98412e)