{"record":{"id":"a2e6a9a3c2c090ab","repo":"dotnet/runtime","slug":"notimplementedexception-typedarray","errorCode":null,"errorMessage":"NotImplementedException: TypedArray","messagePattern":"NotImplementedException: TypedArray","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/marshal-to-cs.ts","lineNumber":417,"sourceCode":"            } 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);\n            } else if (value instanceof Int16Array\n                || value instanceof Int8Array\n                || value instanceof Uint8ClampedArray\n                || value instanceof Uint16Array\n                || value instanceof Uint32Array\n            ) {\n                throw new Error(\"NotImplementedException: TypedArray\");\n            } else if (isThenable(value)) {\n                marshal_task_to_cs(arg, value);\n            } else if (value instanceof Span) {\n                throw new Error(\"NotImplementedException: Span\");\n            } else if (js_type == \"object\") {\n                const js_handle = mono_wasm_get_js_handle(value);\n                set_arg_type(arg, MarshalerType.JSObject);\n                if (BuildConfiguration === \"Debug\" && Object.isExtensible(value)) {\n                    value[proxy_debug_symbol] = `JS Object with JSHandle ${js_handle}`;\n                }\n                set_js_handle(arg, js_handle);\n            } else {\n                throw new Error(`JSObject proxy is not supported for ${js_type} ${value}`);\n            }\n        } else {\n            assert_not_disposed(value);\n            if (value instanceof ArraySegment) {\n                throw new Error(\"NotImplementedException: ArraySegment. \" + jsinteropDoc);","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/marshal-to-cs.ts#L399-L435","documentation":"Thrown by marshal_cs_object_to_cs() when a JS TypedArray of an unsupported type is passed to a C# 'object' parameter. The supported TypedArrays are Uint8Array (Byte), Float32Array (Single), Float64Array (Double), and Int32Array (Int32). Unsupported types that trigger this error are Int16Array, Int8Array, Uint8ClampedArray, Uint16Array, and Uint32Array. These element types do not have dedicated marshalers in the object marshaling path.","triggerScenarios":"Passing an Int16Array, Int8Array, Uint8ClampedArray, Uint16Array, or Uint32Array to a C# method whose parameter is typed as 'object'. The marshal_cs_object_to_cs function matches the instanceof checks for these types and explicitly throws.","commonSituations":"Using WebGL or Canvas APIs that return Uint16Array/Uint32Array buffers and passing them to C# as object. Interfacing with image processing libraries that produce Uint16Array pixel data. Confusing the set of supported TypedArray element types.","solutions":["Convert the unsupported TypedArray to a supported type before passing: wrap in Uint8Array (e.g., new Uint8Array(array.buffer)) and use a byte[] parameter on the C# side.","If the C# side needs Int16 or Uint32 data, declare the parameter as int[] (Int32Array) and convert values, or use a byte[] and reinterpret on the C# side.","Declare the C# parameter as a specific array type (e.g., byte[], int[]) so the array marshaler with the correct element_type is used instead of the object marshaler.","Convert to a plain JS Array and let the Object array marshaler handle it element by element."],"exampleFix":"// before (unsupported TypedArray to object parameter)\n// C#: [JSExport] public static void Process(object data) { }\n// JS:  Process(new Uint16Array([1, 2, 3])); // throws\n\n// after (convert to Uint8Array or use specific type)\n// C#: [JSExport] public static void Process(byte[] data) { }\n// JS:  const u8 = new Uint8Array(uint16Array.buffer);\n//      Process(u8);","handlingStrategy":"type-guard","validationCode":"// Check TypedArray type before passing to C# object parameter\nconst supportedTypedArrays = [Uint8Array, Float32Array, Float64Array, Int32Array];\nfunction isSupportedTypedArray(value: any): boolean {\n  return supportedTypedArray.some(TA => value instanceof TA);\n}\n\nfunction convertTypedArray(value: TypedArray): Uint8Array {\n  // Convert any TypedArray to Uint8Array view over the same buffer\n  return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);\n}","typeGuard":"function isUnsupportedTypedArray(value: unknown): boolean {\n  return value instanceof Int16Array\n    || value instanceof Int8Array\n    || value instanceof Uint8ClampedArray\n    || value instanceof Uint16Array\n    || value instanceof Uint32Array;\n}","tryCatchPattern":null,"preventionTips":["Convert Int16Array/Uint16Array/Uint32Array to Uint8Array (byte view) before passing to C#.","Declare C# parameters as byte[] or int[] instead of object for array data.","Use the buffer property to create a byte-level view: new Uint8Array(array.buffer)."],"tags":["marshaling","typedarray","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"}