{"record":{"id":"9f3295e6f5cfb20a","repo":"dotnet/runtime","slug":"notimplementedexception-elementtype","errorCode":null,"errorMessage":"NotImplementedException ${elementType} ","messagePattern":"NotImplementedException (.+?) ","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/marshal-to-cs.ts","lineNumber":517,"sourceCode":"    dotnetAssert.check(gcHandle, \"Only roundtrip of ArraySegment instance created by C#\");\n    checkViewType(elementType, value._viewType);\n    setArgType(arg, MarshalerType.ArraySegment);\n    setArgIntptr(arg, value._pointer);\n    setArgLength(arg, value.length);\n    setGcHandle(arg, gcHandle);\n}\n\nfunction checkViewType(elementType: MarshalerType, viewType: MemoryViewType) {\n    if (elementType == MarshalerType.Byte) {\n        dotnetAssert.check(MemoryViewType.Byte == viewType, \"Expected MemoryViewType.Byte\");\n    } else if (elementType == MarshalerType.Int32) {\n        dotnetAssert.check(MemoryViewType.Int32 == viewType, \"Expected MemoryViewType.Int32\");\n    } else if (elementType == MarshalerType.Double) {\n        dotnetAssert.check(MemoryViewType.Double == viewType, \"Expected MemoryViewType.Double\");\n    } else if (elementType == MarshalerType.Single) {\n        dotnetAssert.check(MemoryViewType.Single == viewType, \"Expected MemoryViewType.Single\");\n    } else {\n        throw new Error(`NotImplementedException ${elementType} `);\n    }\n}\n\n","sourceCodeStart":499,"sourceCodeEnd":521,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/marshal-to-cs.ts#L499-L521","documentation":"Thrown by checkViewType (marshal-to-cs.ts) when validating that a Span/ArraySegment's MemoryViewType matches the requested elementType. Only Byte, Int32, Double, and Single element types are accepted; any other elementType is rejected before the view is used.","triggerScenarios":"Calling _marshalSpanToCs/_marshalArraySegmentToCs with elementType other than Byte/Int32/Double/Single, or a Span<T> whose declared T doesn't map onto those four views (e.g. Span<char>, Span<decimal>).","commonSituations":"Declaring Span<char> or Span<bool> on a C# interop method; mismatch between the C# element type and the MemoryViewType the runtime allocated.","solutions":["Use Span<byte>/Span<int>/Span<double>/Span<float> on the C# interop boundary.","For char, use Span<byte> or Span<int> and reinterpret on the C# side.","If you need other element types, copy into a supported view before crossing the boundary."],"exampleFix":"// before\nstatic partial void Process(Span<char> data);\n\n// after\nstatic partial void Process(Span<byte> data); // or Span<int>","handlingStrategy":"validation","validationCode":"const SUPPORTED_SPAN_ELEMENT = new Set([\"Byte\",\"Int32\",\"Double\",\"Single\"]);\nfunction checkSpanElement(jsType: string) {\n    if (!SUPPORTED_SPAN_ELEMENT.has(jsType)) throw new Error(`Unsupported Span element: ${jsType}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only Span<byte/int/double/float> at the interop boundary.","For other T, copy into a supported view before marshaling."],"tags":["marshaling","span","element-type","interop"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}