dotnet/runtime · error · Error

NotImplementedException ${element_type}

Error message

NotImplementedException ${element_type} 

What it means

checkViewType (used by _marshal_span_to_cs and _marshal_array_segment_to_cs) accepts only Byte, Int32, Double, and Single element types. Any other MarshalerType reaches the default branch and throws with the element_type name. This validates that a JS-constructed Span/ArraySegment matches its declared element type.

Source

Thrown at src/mono/browser/runtime/marshal-to-cs.ts:553

    mono_assert(gc_handle, "Only roundtrip of ArraySegment instance created by C#");
    checkViewType(element_type, value._viewType);
    set_arg_type(arg, MarshalerType.ArraySegment);
    set_arg_intptr(arg, value._pointer);
    set_arg_length(arg, value.length);
    set_gc_handle(arg, gc_handle);
}

function checkViewType (element_type: MarshalerType, viewType: MemoryViewType) {
    if (element_type == MarshalerType.Byte) {
        mono_check(MemoryViewType.Byte == viewType, "Expected MemoryViewType.Byte");
    } else if (element_type == MarshalerType.Int32) {
        mono_check(MemoryViewType.Int32 == viewType, "Expected MemoryViewType.Int32");
    } else if (element_type == MarshalerType.Double) {
        mono_check(MemoryViewType.Double == viewType, "Expected MemoryViewType.Double");
    } else if (element_type == MarshalerType.Single) {
        mono_check(MemoryViewType.Single == viewType, "Expected MemoryViewType.Single");
    } else {
        throw new Error(`NotImplementedException ${element_type} `);
    }
}

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Use one of the supported element types: Byte (Uint8Array), Int32 (Int32Array), Double (Float64Array), or Single (Float32Array).
  2. Repack data from the unsupported width into a supported typed array before constructing the Span/ArraySegment.

Example fix

// before
new Span(ptr, len, MemoryViewType.Int16); // element_type unsupported -> throws
// after
// repack into Int32Array and use MemoryViewType.Int32
Defensive patterns

Strategy: validation

Validate before calling

const OK = new Set(['Byte','Int32','Double','Single']);
if (value && value._viewType && !OK.has(value._viewType)) {
  throw new TypeError(`Span/ArraySegment element type ${value._viewType} is unsupported; use Byte/Int32/Double/Single.`);
}

Type guard

function isSupportedViewType(t: string): boolean { return t === 'Byte' || t === 'Int32' || t === 'Double' || t === 'Single'; }

Prevention

When it happens

Trigger: Constructing or passing a Span/ArraySegment whose element_type (MemoryViewType) is not one of Byte/Int32/Double/Single when marshaling to C#.

Common situations: Trying to use Int16/UInt16/UInt32-backed memory views; a custom Span wrapper with an unsupported view type.

Related errors


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