{"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/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/marshal-to-cs.ts#L535-L557","documentation":"Thrown by checkViewType() when the element_type of a Span or ArraySegment does not match any of the four supported view types (Byte, Int32, Double, Single). checkViewType validates that the MemoryViewType of a Span/ArraySegment matches the expected element type. If the element_type falls through all four checks, the function throws with the element_type included for diagnosis.","triggerScenarios":"Creating or receiving a Span/ArraySegment with an element type other than Byte, Int32, Double, or Single, and then passing it through a marshaling path that calls checkViewType. This occurs in _marshal_span_to_cs and _marshal_array_segment_to_cs when validating the view type against the expected C# element type.","commonSituations":"Declaring a C# Span<T> or ArraySegment<T> with T as an unsupported type (e.g., Span<short>, Span<char>, Span<long>). Mismatched element types between the JS Span wrapper and the C# parameter declaration.","solutions":["Use one of the four supported Span/ArraySegment element types: Span<byte>, Span<int>, Span<double>, or Span<float>.","For Span<short> or Span<char>, use Span<byte> or Span<int> and reinterpret/convert on the C# side.","For Span<long>, use Span<byte> and read values manually, or switch to passing a long[] array if supported.","Ensure the MemoryViewType of the JS-side Span matches the C# element type."],"exampleFix":"// before (unsupported Span element type)\n// C#: [JSExport] public static void Process(Span<short> data) { }\n\n// after (use supported type)\n// C#: [JSExport] public static void Process(Span<byte> data) { }\n// then reinterpret bytes as shorts on the C# side","handlingStrategy":"validation","validationCode":"// Validate Span/ArraySegment element type\nconst supportedViewTypes = new Set(['Byte', 'Int32', 'Double', 'Single']);\nfunction isSupportedViewType(type: string): boolean {\n  return supportedViewTypes.has(type);\n}\n\n// Ensure C# Span/ArraySegment uses byte, int, double, or float","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use Span<byte>, Span<int>, Span<double>, or Span<float> for interop.","Convert Span<short>, Span<char> to Span<byte> and reinterpret on the receiving side.","Match MemoryViewType to the C# element type when creating JS-side Span/ArraySegment."],"tags":["marshaling","span","arraysegment","type-mismatch","interop"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}