dotnet/runtime · error · Error
NotImplementedException: ArraySegment. For more information…
Error message
NotImplementedException: ArraySegment. For more information see https://aka.ms/dotnet-wasm-jsinterop
What it means
Thrown by marshal_cs_object_to_cs() when an ArraySegment value (that has a C# gc_handle, i.e., it was created by C# and received by JS) is passed back to a C# method whose parameter is 'object'. The runtime supports round-tripping ArraySegments only through the dedicated ArraySegment<T> marshaler (_marshal_array_segment_to_cs), not through the generic object marshaler. If C# declares the parameter as 'object', the marshal_cs_object_to_cs function encounters the ArraySegment and explicitly throws.
Solutions
- Declare the C# receiving parameter as ArraySegment<T> (e.g., ArraySegment<byte>) with the matching element type so the _marshal_array_segment_to_cs marshaler handles it.
- If you need to pass it as object, extract the underlying data first: read the ArraySegment's buffer into a Uint8Array and pass that as byte[].
- Keep the ArraySegment reference and pass it only to methods with explicit ArraySegment<T> parameters.
- Redesign the loosely-typed object API to use specific types.
Example fix
// before (ArraySegment passed to object parameter)
// C#: [JSExport] public static void Consume(object data) { }
// JS: const seg = GetArraySegmentFromCSharp();
// Consume(seg); // throws NotImplementedException: ArraySegment
// after (use ArraySegment<byte> parameter)
// C#: [JSExport] public static void Consume(ArraySegment<byte> data) { }
// JS: Consume(seg); // works via _marshal_array_segment_to_cs Defensive patterns
Strategy: type-guard
Validate before calling
// Check if value is an ArraySegment before passing to object parameter
function isArraySegment(value: any): boolean {
return value !== null && typeof value === 'object' && value.constructor && value.constructor.name === 'ArraySegment';
}
if (isArraySegment(myValue)) {
// use ArraySegment<T> parameter or copy data
throw new Error('Use ArraySegment<T> parameter for ArraySegment values, not object');
} Type guard
function isArraySegmentLike(value: unknown): boolean {
return value !== null && typeof value === 'object'
&& '_pointer' in (value as any)
&& 'length' in (value as any)
&& '_viewType' in (value as any)
&& js_owned_gc_handle_symbol in (value as any);
} Prevention
- Always declare C# parameters as ArraySegment<T> when receiving ArraySegment values.
- Never forward C#-created ArraySegments to methods with 'object' parameters.
- If a generic API is needed, copy the ArraySegment data to a byte[] first.
When it happens
Trigger: Receiving an ArraySegment<T> from a C# JSExport, then passing it to another C# method whose parameter is declared as 'object' instead of ArraySegment<T>. The value has a gc_handle (from setup_managed_proxy in _marshal_array_segment_to_js), so it enters the gc_handle-defined branch at line 434.
Common situations: Forwarding a C#-created ArraySegment to a different C# method with a loose 'object' signature. Using a generic object-passing API to relay managed values.
Related errors
- NotImplementedException
- JSObject proxy is not supported for
- not implemented
- NotImplementedException: bigint
- NotImplementedException
AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10).
Data as JSON: /api/errors/6fb4b7d376f4fdeb.
Report an issue: GitHub.
Appendix: source
Thrown at src/mono/browser/runtime/marshal-to-cs.ts:435
throw new Error("NotImplementedException: TypedArray");
} else if (isThenable(value)) {
marshal_task_to_cs(arg, value);
} else if (value instanceof Span) {
throw new Error("NotImplementedException: Span");
} else if (js_type == "object") {
const js_handle = mono_wasm_get_js_handle(value);
set_arg_type(arg, MarshalerType.JSObject);
if (BuildConfiguration === "Debug" && Object.isExtensible(value)) {
value[proxy_debug_symbol] = `JS Object with JSHandle ${js_handle}`;
}
set_js_handle(arg, js_handle);
} else {
throw new Error(`JSObject proxy is not supported for ${js_type} ${value}`);
}
} else {
assert_not_disposed(value);
if (value instanceof ArraySegment) {
throw new Error("NotImplementedException: ArraySegment. " + jsinteropDoc);
} else if (value instanceof ManagedError) {
set_arg_type(arg, MarshalerType.Exception);
set_gc_handle(arg, gc_handle);
} else if (value instanceof ManagedObject) {
set_arg_type(arg, MarshalerType.Object);
set_gc_handle(arg, gc_handle);
} else {
throw new Error("NotImplementedException " + js_type + ". " + jsinteropDoc);
}
}
}
}
export function marshal_array_to_cs (arg: JSMarshalerArgument, value: Array<any> | TypedArray | undefined | null, element_type?: MarshalerType): void {
mono_assert(!!element_type, "Expected valid element_type parameter");
marshal_array_to_cs_impl(arg, value, element_type);
}
View on GitHub (pinned to 60108ba66e)