{"record":{"id":"36b13ff7bdc5d223","repo":"dotnet/runtime","slug":"notimplementedexception-bigint","errorCode":null,"errorMessage":"NotImplementedException: bigint","messagePattern":"NotImplementedException: bigint","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/marshal-to-cs.ts","lineNumber":392,"sourceCode":"}\n\nexport function marshal_cs_object_to_cs (arg: JSMarshalerArgument, value: any): void {\n    if (value === undefined || value === null) {\n        set_arg_type(arg, MarshalerType.None);\n        set_arg_proxy_context(arg);\n    } else {\n        const gc_handle = value[js_owned_gc_handle_symbol];\n        const js_type = typeof (value);\n        if (gc_handle === undefined) {\n            if (js_type === \"string\" || js_type === \"symbol\") {\n                set_arg_type(arg, MarshalerType.String);\n                _marshal_string_to_cs_impl(arg, value);\n            } else if (js_type === \"number\") {\n                set_arg_type(arg, MarshalerType.Double);\n                set_arg_f64(arg, value);\n            } else if (js_type === \"bigint\") {\n                // we do it because not all bigint values could fit into Int64\n                throw new Error(\"NotImplementedException: bigint\");\n            } else if (js_type === \"boolean\") {\n                set_arg_type(arg, MarshalerType.Boolean);\n                set_arg_bool(arg, value);\n            } else if (value instanceof Date) {\n                set_arg_type(arg, MarshalerType.DateTime);\n                set_arg_date(arg, value);\n            } else if (value instanceof Error) {\n                marshal_exception_to_cs(arg, value);\n            } else if (value instanceof Uint8Array) {\n                marshal_array_to_cs_impl(arg, value, MarshalerType.Byte);\n            } else if (value instanceof Float32Array) {\n                marshal_array_to_cs_impl(arg, value, MarshalerType.Single);\n            } else if (value instanceof Float64Array) {\n                marshal_array_to_cs_impl(arg, value, MarshalerType.Double);\n            } else if (value instanceof Int32Array) {\n                marshal_array_to_cs_impl(arg, value, MarshalerType.Int32);\n            } else if (Array.isArray(value)) {\n                marshal_array_to_cs_impl(arg, value, MarshalerType.Object);","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/marshal-to-cs.ts#L374-L410","documentation":"Thrown by marshal_cs_object_to_cs() when a JS value of type 'bigint' (without a C# gc_handle) is passed to a C# method whose parameter is typed as 'object'. The runtime supports marshaling bigint to C# Int64 only when the parameter is explicitly typed as long/Int64 (via the BigInt64 marshaler). When the parameter is 'object', the marshaler does not know the target type and cannot convert an arbitrary-precision bigint, so it throws NotImplementedException. This is in the gc_handle === undefined branch.","triggerScenarios":"Passing a JS bigint (e.g., 123n) to a C# method whose parameter is declared as 'object' rather than 'long' or 'Int64'. The marshal_cs_object_to_cs function is invoked because the C# signature uses MarshalerType.Object, and the js_type is 'bigint' which has no object marshaler.","commonSituations":"Using [JSImport] or [JSExport] with an 'object' parameter and passing a bigint from JS. Mixed-type APIs that accept object and receive bigint values. Confusion between C# long (which needs the specific marshaler) and object.","solutions":["Declare the C# parameter as 'long' (or 'long?' for nullable) instead of 'object' so the BigInt64 marshaler is used.","Convert the bigint to a number before passing if the value fits in a safe integer: Number(value).","Convert the bigint to a string and parse it on the C# side if precision is needed but the parameter must remain object.","Wrap the value in a JS object and pass it as a JSObject proxy if you need an opaque handle."],"exampleFix":"// before (C# method takes object, JS passes bigint)\n// C#: [JSExport] public static void Foo(object value) { }\n// JS:  Foo(123n); // throws NotImplementedException: bigint\n\n// after (C# method takes long)\n// C#: [JSExport] public static void Foo(long value) { }\n// JS:  Foo(123n); // works via BigInt64 marshaler","handlingStrategy":"type-guard","validationCode":"// Validate value type before passing to C# object parameter\nfunction safeMarshal(value: any): any {\n  if (typeof value === 'bigint') {\n    // convert to number if safe, else throw with guidance\n    if (value >= Number.MIN_SAFE_INTEGER && value <= Number.MAX_SAFE_INTEGER) {\n      return Number(value);\n    }\n    throw new Error('BigInt too large for number; declare C# parameter as long instead of object');\n  }\n  return value;\n}","typeGuard":"function isBigInt(value: unknown): value is bigint {\n  return typeof value === 'bigint';\n}","tryCatchPattern":null,"preventionTips":["Declare C# interop parameters with explicit types (long, long?) instead of object for numeric values.","Convert bigint to number before passing if the value fits in a safe integer.","Never pass raw bigint to a loosely-typed 'object' parameter."],"tags":["marshaling","bigint","type-mismatch","interop"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}