{"record":{"id":"6fb4b7d376f4fdeb","repo":"dotnet/runtime","slug":"notimplementedexception-arraysegment-for-more-in","errorCode":null,"errorMessage":"NotImplementedException: ArraySegment. For more information see https://aka.ms/dotnet-wasm-jsinterop","messagePattern":"NotImplementedException: ArraySegment\\. For more information see https://aka\\.ms/dotnet-wasm-jsinterop","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/marshal-to-cs.ts","lineNumber":435,"sourceCode":"                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);\n            } else if (value instanceof ManagedError) {\n                set_arg_type(arg, MarshalerType.Exception);\n                set_gc_handle(arg, gc_handle);\n            } else if (value instanceof ManagedObject) {\n                set_arg_type(arg, MarshalerType.Object);\n                set_gc_handle(arg, gc_handle);\n            } else {\n                throw new Error(\"NotImplementedException \" + js_type + \". \" + jsinteropDoc);\n            }\n        }\n    }\n}\n\nexport function marshal_array_to_cs (arg: JSMarshalerArgument, value: Array<any> | TypedArray | undefined | null, element_type?: MarshalerType): void {\n    mono_assert(!!element_type, \"Expected valid element_type parameter\");\n    marshal_array_to_cs_impl(arg, value, element_type);\n}\n","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/mono/browser/runtime/marshal-to-cs.ts#L417-L453","documentation":"marshal_cs_object_to_cs throws when value is an ArraySegment (it carries a gc_handle, so it is a managed proxy) but the C# parameter is the generic object marshaler. ArraySegment is only supported via its own marshaler _marshal_array_segment_to_cs, and even then only for round-trip of instances originally created by C#.","triggerScenarios":"Passing a JS ArraySegment object to a C# [JSExport] parameter typed as object/JSObject instead of ArraySegment<T>.","commonSituations":"Round-tripping an ArraySegment returned from C# back into a generic API; passing a memory segment to a loosely-typed method.","solutions":["Declare the C# parameter as ArraySegment<T> (byte/int/double/float element) so the dedicated marshaler is used.","Copy the segment data into a supported array (Uint8Array/Int32Array/Float32Array/Float64Array) and pass that instead."],"exampleFix":"// C# before\n[JSExport] public static void Take(object v) { }\n// JS: dotnet.jsExports.Take(segFromCs); // throws\n// C# after\n[JSExport] public static void Take(ArraySegment<byte> v) { }","handlingStrategy":"type-guard","validationCode":"if (value && value instanceof ArraySegment) throw new TypeError('Pass an ArraySegment only to a C# ArraySegment<T> parameter, not object/JSObject.');","typeGuard":"function isArraySegment(v: unknown): boolean { return v != null && typeof v === 'object' && v instanceof ArraySegment; }","tryCatchPattern":null,"preventionTips":["Declare C# parameters that receive segments as ArraySegment<T>.","Do not route ArraySegment through object-typed APIs; copy into a supported array first.","Keep element types to byte/int/double/float."],"tags":["marshaling","interop","arraysegment"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}