{"record":{"id":"01fb5ded23e1a2d0","repo":"dotnet/runtime","slug":"notimplementedexception-element-type","errorCode":null,"errorMessage":"NotImplementedException ${element_type} ","messagePattern":"NotImplementedException (.+?) ","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/marshal-to-cs.ts","lineNumber":553,"sourceCode":"    mono_assert(gc_handle, \"Only roundtrip of ArraySegment instance created by C#\");\n    checkViewType(element_type, value._viewType);\n    set_arg_type(arg, MarshalerType.ArraySegment);\n    set_arg_intptr(arg, value._pointer);\n    set_arg_length(arg, value.length);\n    set_gc_handle(arg, gc_handle);\n}\n\nfunction checkViewType (element_type: MarshalerType, viewType: MemoryViewType) {\n    if (element_type == MarshalerType.Byte) {\n        mono_check(MemoryViewType.Byte == viewType, \"Expected MemoryViewType.Byte\");\n    } else if (element_type == MarshalerType.Int32) {\n        mono_check(MemoryViewType.Int32 == viewType, \"Expected MemoryViewType.Int32\");\n    } else if (element_type == MarshalerType.Double) {\n        mono_check(MemoryViewType.Double == viewType, \"Expected MemoryViewType.Double\");\n    } else if (element_type == MarshalerType.Single) {\n        mono_check(MemoryViewType.Single == viewType, \"Expected MemoryViewType.Single\");\n    } else {\n        throw new Error(`NotImplementedException ${element_type} `);\n    }\n}\n\n","sourceCodeStart":535,"sourceCodeEnd":557,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/mono/browser/runtime/marshal-to-cs.ts#L535-L557","documentation":"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.","triggerScenarios":"Constructing or passing a Span/ArraySegment whose element_type (MemoryViewType) is not one of Byte/Int32/Double/Single when marshaling to C#.","commonSituations":"Trying to use Int16/UInt16/UInt32-backed memory views; a custom Span wrapper with an unsupported view type.","solutions":["Use one of the supported element types: Byte (Uint8Array), Int32 (Int32Array), Double (Float64Array), or Single (Float32Array).","Repack data from the unsupported width into a supported typed array before constructing the Span/ArraySegment."],"exampleFix":"// before\nnew Span(ptr, len, MemoryViewType.Int16); // element_type unsupported -> throws\n// after\n// repack into Int32Array and use MemoryViewType.Int32","handlingStrategy":"validation","validationCode":"const OK = new Set(['Byte','Int32','Double','Single']);\nif (value && value._viewType && !OK.has(value._viewType)) {\n  throw new TypeError(`Span/ArraySegment element type ${value._viewType} is unsupported; use Byte/Int32/Double/Single.`);\n}","typeGuard":"function isSupportedViewType(t: string): boolean { return t === 'Byte' || t === 'Int32' || t === 'Double' || t === 'Single'; }","tryCatchPattern":null,"preventionTips":["Construct Span/ArraySegment only with Byte/Int32/Double/Single element types.","Repack data from unsupported widths (Int16/Uint16/Uint32) into a supported typed array first.","Align the JS typed array (Uint8Array/Int32Array/Float32Array/Float64Array) with the declared element type."],"tags":["marshaling","interop","span","arraysegment","typedarray"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}