ElectronNET/Electron.NET · error · JsonException

Unexpected end while reading property value.

Error message

Unexpected end while reading property value.

What it means

In JsonToBoxedPrimitivesConverter.ReadValue, after successfully reading a property name inside an object the converter calls r.Read() to advance to the value; if the reader reaches the end of the JSON first (returns false), it throws this JsonException. It means the JSON ended in the middle of an object property.

Solutions

  1. Verify the JSON payload is complete (balanced braces/quotes) before sending
  2. Log the raw payload length and content on error to confirm truncation
  3. Increase buffer/pipe size limits if large payloads get truncated
  4. Validate with JSON.parse on the sending side

Example fix

// before
// sending '{ "width":' (truncated)
// after
// sending complete JSON: '{ "width": 800 }'
JSON.stringify(options); // ensure the full string is transmitted
Defensive patterns

Strategy: try-catch

Validate before calling

// sender: confirm complete transmission
const json = JSON.stringify(msg);
socket.write(json, () => console.assert(JSON.parse(json) !== undefined));

Try / catch

try
{
    var value = JsonSerializer.Deserialize<object>(json, ElectronJson.Options);
}
catch (JsonException ex)
{
    logger.LogWarning(ex, "Truncated JSON received ({Len} bytes): {Raw}", json?.Length, json);
}

Prevention

When it happens

Trigger: A JSON object truncated right after a property name, e.g. '{ "width":' or '{ "width" }' with no value; IPC payloads cut off mid-transmission.

Common situations: Network/IPC message truncation; string truncation from fixed-size buffers; incomplete serialization before the payload was sent.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of ElectronNET/Electron.NET@87cc6f98b6 (2026-09-14). Data as JSON: /api/errors/3d8b8e1f8c3168d3. Report an issue: GitHub.

Appendix: source

Thrown at src/ElectronNET.API/Serialization/JsonToBoxedPrimitivesConverter.cs:37

                case JsonTokenType.StartObject:

                    var obj = new Dictionary<string, object>();
                    while (r.Read())
                    {
                        if (r.TokenType == JsonTokenType.EndObject)
                        {
                            return obj;
                        }

                        if (r.TokenType != JsonTokenType.PropertyName)
                        {
                            throw new JsonException("Expected property name.");
                        }

                        string name = r.GetString()!;
                        if (!r.Read())
                        {
                            throw new JsonException("Unexpected end while reading property value.");
                        }

                        obj[name] = ReadValue(ref r);
                    }

                    throw new JsonException("Unexpected end while reading object.");

                case JsonTokenType.StartArray:

                    var list = new List<object>();
                    while (r.Read())
                    {
                        if (r.TokenType == JsonTokenType.EndArray)
                        {
                            return list;
                        }

                        list.Add(ReadValue(ref r));

View on GitHub (pinned to 87cc6f98b6)