dotnet/runtime · error · Error
NotImplementedException ${elementType}
Error message
NotImplementedException ${elementType} What it means
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.
Source
Thrown at src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/marshal-to-cs.ts:517
dotnetAssert.check(gcHandle, "Only roundtrip of ArraySegment instance created by C#");
checkViewType(elementType, value._viewType);
setArgType(arg, MarshalerType.ArraySegment);
setArgIntptr(arg, value._pointer);
setArgLength(arg, value.length);
setGcHandle(arg, gcHandle);
}
function checkViewType(elementType: MarshalerType, viewType: MemoryViewType) {
if (elementType == MarshalerType.Byte) {
dotnetAssert.check(MemoryViewType.Byte == viewType, "Expected MemoryViewType.Byte");
} else if (elementType == MarshalerType.Int32) {
dotnetAssert.check(MemoryViewType.Int32 == viewType, "Expected MemoryViewType.Int32");
} else if (elementType == MarshalerType.Double) {
dotnetAssert.check(MemoryViewType.Double == viewType, "Expected MemoryViewType.Double");
} else if (elementType == MarshalerType.Single) {
dotnetAssert.check(MemoryViewType.Single == viewType, "Expected MemoryViewType.Single");
} else {
throw new Error(`NotImplementedException ${elementType} `);
}
}
View on GitHub (pinned to 290d5ab72c)
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.
Example fix
// before static partial void Process(Span<char> data); // after static partial void Process(Span<byte> data); // or Span<int>
Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED_SPAN_ELEMENT = new Set(["Byte","Int32","Double","Single"]);
function checkSpanElement(jsType: string) {
if (!SUPPORTED_SPAN_ELEMENT.has(jsType)) throw new Error(`Unsupported Span element: ${jsType}`);
} Prevention
- Use only Span<byte/int/double/float> at the interop boundary.
- For other T, copy into a supported view before marshaling.
When it happens
Trigger: 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>).
Common situations: Declaring Span<char> or Span<bool> on a C# interop method; mismatch between the C# element type and the MemoryViewType the runtime allocated.
Related errors
- NotImplementedException: Span
- NotImplementedException ${element_type}
- NotImplementedException: Span
- not implemented
- NotImplementedException ${elementType}. For more information
AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06).
Data as JSON: /api/errors/9f3295e6f5cfb20a.
Report an issue: GitHub.