{"record":{"id":"afe040bd0b951a89","repo":"dotnet/runtime","slug":"notimplementedexception-bigint-afe040","errorCode":null,"errorMessage":"NotImplementedException: bigint","messagePattern":"NotImplementedException: bigint","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/marshal-to-cs.ts","lineNumber":363,"sourceCode":"}\n\nexport function marshalCsObjectToCs(arg: JSMarshalerArgument, value: any): void {\n    if (value === undefined || value === null) {\n        setArgType(arg, MarshalerType.None);\n        setArgProxyContext(arg);\n    } else {\n        const gcHandle = value[jsOwnedGcHandleSymbol];\n        const jsType = typeof (value);\n        if (gcHandle === undefined) {\n            if (jsType === \"string\" || jsType === \"symbol\") {\n                setArgType(arg, MarshalerType.String);\n                _marshalStringToCsImpl(arg, value);\n            } else if (jsType === \"number\") {\n                setArgType(arg, MarshalerType.Double);\n                setArgF64(arg, value);\n            } else if (jsType === \"bigint\") {\n                // we do it because not all bigint values could fit into Int64\n                throw new Error(\"NotImplementedException: bigint\");\n            } else if (jsType === \"boolean\") {\n                setArgType(arg, MarshalerType.Boolean);\n                setArgBool(arg, value);\n            } else if (value instanceof Date) {\n                setArgType(arg, MarshalerType.DateTime);\n                setArgDate(arg, value);\n            } else if (value instanceof Error) {\n                marshalExceptionToCs(arg, value);\n            } else if (value instanceof Uint8Array) {\n                marshalArrayToCsImpl(arg, value, MarshalerType.Byte);\n            } else if (value instanceof Float64Array) {\n                marshalArrayToCsImpl(arg, value, MarshalerType.Double);\n            } else if (value instanceof Float32Array) {\n                marshalArrayToCsImpl(arg, value, MarshalerType.Single);\n            } else if (value instanceof Int32Array) {\n                marshalArrayToCsImpl(arg, value, MarshalerType.Int32);\n            } else if (Array.isArray(value)) {\n                marshalArrayToCsImpl(arg, value, MarshalerType.Object);","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/marshal-to-cs.ts#L345-L381","documentation":"marshalCsObjectToCs handles a JS value of type 'bigint' when the value has no jsOwnedGcHandleSymbol (i.e. it is a raw bigint being marshaled as a generic object, not a managed Int64). The marshaler does not attempt to coerce arbitrary-precision bigints into a .NET object and throws NotImplementedException. Use a typed Int64/Int52 parameter or BigInt64 marshaler instead.","triggerScenarios":"A JS function invoked from C# via JSImport returns or passes a JS bigint in a position typed as `object`/JSObject (marshalCsObjectToCs path) rather than a parameter explicitly marshaled as BigInt64/Int64. For example returning BigInt(...) from a JS function whose [return: ...] is object.","commonSituations":"Returning BigInt(...) from a JS interop function while the C# side declares the return as object or lacks the explicit [return: MarshalAs(... BigInt64)]; passing a bigint into a params object[] array; third-party JS lib returning bigints through interop.","solutions":["Declare the C# signature with an explicit long/Int64 (or long[]) parameter/return and the BigInt64 marshaler so the value goes through _marshalBigint64ToCs instead of the object path.","If the value may exceed Int64 range, convert it to a string in JS and parse on the C# side (long.Parse / BigInteger.Parse).","Avoid returning raw bigints from interop functions typed as object; pick a concrete primitive or JSObject marshaling."],"exampleFix":"// before - C#\n[return: MarshalAs(typeof(object))]\n[JSImport(\"big\", \"m\")]\nstatic partial object Big(); // JS returns BigInt(123) -> throws\n\n// after\n[return: MarshalAs(typeof(long))]\n[JSImport(\"big\", \"m\")]\nstatic partial long Big(); // routed through BigInt64 marshaler","handlingStrategy":"type-guard","validationCode":"// On the JS side, avoid returning a raw bigint through an object-typed boundary.\nfunction safeReturn(value: unknown): unknown {\n  if (typeof value === \"bigint\") {\n    // marshal as Int64-friendly value or string\n    return value.toString(); // parse with long.Parse / BigInteger.Parse on C# side\n  }\n  return value;\n}","typeGuard":"function isBigint(v: unknown): v is bigint {\n  return typeof v === \"bigint\";\n}","tryCatchPattern":"null","preventionTips":["Declare C# interop params/returns as long/Int64 with the BigInt64 marshaler instead of object.","Convert bigints to strings in JS when the C# side uses object/string typing.","Do not pass bigints into object[]-typed interop params.","Audit third-party JS return values that may be bigints before crossing interop."],"tags":["jsinterop","marshaling","bigint","not-implemented"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}