dotnet/runtime · error · Error

NotImplementedException: bigint

Error message

NotImplementedException: bigint

What it means

Thrown by marshalCsObjectToCs when a JS value being marshaled to a C# 'object' parameter is a primitive bigint (typeof === 'bigint'). The generic object marshaler refuses bigint because arbitrary BigInt values do not always fit into a signed Int64; only the dedicated BigInt64 marshaler is supported. The comment in source explains the deliberate rejection.

Source

Thrown at src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/marshal-to-cs.ts:363

}

export function marshalCsObjectToCs(arg: JSMarshalerArgument, value: any): void {
    if (value === undefined || value === null) {
        setArgType(arg, MarshalerType.None);
        setArgProxyContext(arg);
    } else {
        const gcHandle = value[jsOwnedGcHandleSymbol];
        const jsType = typeof (value);
        if (gcHandle === undefined) {
            if (jsType === "string" || jsType === "symbol") {
                setArgType(arg, MarshalerType.String);
                _marshalStringToCsImpl(arg, value);
            } else if (jsType === "number") {
                setArgType(arg, MarshalerType.Double);
                setArgF64(arg, value);
            } else if (jsType === "bigint") {
                // we do it because not all bigint values could fit into Int64
                throw new Error("NotImplementedException: bigint");
            } else if (jsType === "boolean") {
                setArgType(arg, MarshalerType.Boolean);
                setArgBool(arg, value);
            } else if (value instanceof Date) {
                setArgType(arg, MarshalerType.DateTime);
                setArgDate(arg, value);
            } else if (value instanceof Error) {
                marshalExceptionToCs(arg, value);
            } else if (value instanceof Uint8Array) {
                marshalArrayToCsImpl(arg, value, MarshalerType.Byte);
            } else if (value instanceof Float64Array) {
                marshalArrayToCsImpl(arg, value, MarshalerType.Double);
            } else if (value instanceof Float32Array) {
                marshalArrayToCsImpl(arg, value, MarshalerType.Single);
            } else if (value instanceof Int32Array) {
                marshalArrayToCsImpl(arg, value, MarshalerType.Int32);
            } else if (Array.isArray(value)) {
                marshalArrayToCsImpl(arg, value, MarshalerType.Object);

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Change the C# parameter/return type to `long` (Int64) and decorate with the BigInt64 marshaler so the dedicated marshaler path is used.
  2. Convert the BigInt to a Number on the JS side (Number(value)) when you are sure it fits in safe-integer range.
  3. If you need arbitrary precision, marshal the value as a string and parse it in C#.

Example fix

// before
[JSImport("globalThis.fns.getBig")] // returns bigint
static partial object GetBig();

// after
[JSImport("globalThis.fns.getBig")]
[return: JSMarshalAsAttribute<JSType.BigInt64>()]
static partial long GetBig();
Defensive patterns

Strategy: type-guard

Validate before calling

function toCsObject(value: unknown): unknown {
    if (typeof value === "bigint") {
        // bigint won't fit the object marshaler; convert or reject
        const n = Number(value);
        if (!Number.isSafeInteger(n)) throw new RangeError("bigint too large for number");
        return n;
    }
    return value;
}

Type guard

const isSafeForCsObject = (v: unknown): boolean =>
    v === null || v === undefined ||
    ["string", "number", "boolean"].includes(typeof v) ||
    v instanceof Date || v instanceof Error ||
    Array.isArray(v) ||
    v instanceof Uint8Array || v instanceof Int32Array ||
    v instanceof Float32Array || v instanceof Float64Array;

Prevention

When it happens

Trigger: Calling a C# method whose parameter is typed `object` (or uses the default object marshaler) from JS and passing a BigInt literal such as 123n. Also hitting this path indirectly when an array of objects contains a bigint element.

Common situations: Passing large integer IDs or timestamps as JS BigInt to a C# interop method declared with `object` instead of `long`/`Int64`; returning bigint from a JS function imported into C# as returning object.

Related errors


AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06). Data as JSON: /api/errors/afe040bd0b951a89. Report an issue: GitHub.