ElectronNET/Electron.NET · error · JsonException

Unsupported token

Error message

Unsupported token {r.TokenType}

What it means

JsonToBoxedPrimitivesConverter.ReadValue handles primitives, objects, arrays, and a few special cases (e.g. Guid/DateTime strings); any remaining JsonTokenType reaches the default branch and throws this JsonException naming the unsupported token. It means the converter received a token kind it was never designed to box.

Solutions

  1. Inspect the logged r.TokenType to see which token is unsupported
  2. Check the expected JSON shape of the API call and send the correct type (number, string, bool, array)
  3. Do not route complex objects through JsonToBoxedPrimitivesConverter; use a typed converter instead
  4. Verify converter registrations in ElectronJson options are not applied to the wrong type

Example fix

// before
// sending an object where a primitive is expected: options = { size: 10 }
send("setSize", options);
// after
send("setSize", 10); // pass the primitive value directly
Defensive patterns

Strategy: validation

Validate before calling

// confirm only primitives/arrays are routed through this converter
bool supported(JsonElement e) => e.ValueKind is
    JsonValueKind.Number or JsonValueKind.String or JsonValueKind.True
    or JsonValueKind.False or JsonValueKind.Null or JsonValueKind.Array;

Try / catch

try
{
    var value = JsonSerializer.Deserialize<object>(json, ElectronJson.Options);
}
catch (JsonException ex) when (ex.Message.Contains("Unsupported token"))
{
    logger.LogWarning(ex, "Unsupported token in payload — check argument shape");
}

Prevention

When it happens

Trigger: Feeding the converter JSON containing token types outside its supported set — e.g. a StartObject/PropertyName at top level where only a primitive/array was expected, or exotic values in an unexpected position.

Common situations: Registering this converter for types it cannot represent; calling Electron APIs with payloads of the wrong shape; deserializing a root value that is an object when a primitive was expected.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

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

                    if (DateTime.TryParse(s, out var dt))
                    {
                        return dt;
                    }

                    if (TimeSpan.TryParse(s, out var ts))
                    {
                        return ts;
                    }

                    if (Guid.TryParse(s, out var g))
                    {
                        return g;
                    }

                    return s;

                default:
                    throw new JsonException($"Unsupported token {r.TokenType}");
            }
        }

        public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options)
        {
            if (value is null)
            {
                writer.WriteNullValue();
                return;
            }

            writer.WriteStartObject();
            writer.WriteEndObject();
        }
    }
}

View on GitHub (pinned to 87cc6f98b6)