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

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#.

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 290d5ab72c)

Solutions

  1. Declare the C# parameter as ArraySegment<T> (byte/int/double/float element) so the dedicated marshaler is used.
  2. Copy the segment data into a supported array (Uint8Array/Int32Array/Float32Array/Float64Array) and pass that instead.

Example fix

// C# before
[JSExport] public static void Take(object v) { }
// JS: dotnet.jsExports.Take(segFromCs); // throws
// C# after
[JSExport] public static void Take(ArraySegment<byte> v) { }
Defensive patterns

Strategy: type-guard

Validate before calling

if (value && value instanceof ArraySegment) throw new TypeError('Pass an ArraySegment only to a C# ArraySegment<T> parameter, not object/JSObject.');

Type guard

function isArraySegment(v: unknown): boolean { return v != null && typeof v === 'object' && v instanceof ArraySegment; }

Prevention

When it happens

Trigger: Passing a JS ArraySegment object to a C# [JSExport] parameter typed as object/JSObject instead of ArraySegment<T>.

Common situations: Round-tripping an ArraySegment returned from C# back into a generic API; passing a memory segment to a loosely-typed method.

Related errors


AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06). Data as JSON: /api/errors/6fb4b7d376f4fdeb. Report an issue: GitHub.