dotnet/runtime · critical · Error
NotImplementedException
Error message
NotImplementedException
What it means
Thrown by MemoryView._unsafe_create_view() in marshal.ts when the memory view's _viewType does not match any of the known MemoryViewType cases (Byte, Int32, Double, Single). It is a developer-facing guard marking an unimplemented code path rather than a user error. Hitting it means the runtime created a MemoryView with a viewType that has no backing TypedArray mapping. This indicates either a new MemoryViewType was added without updating the factory, or memory corruption fed an invalid viewType integer.
Source
Thrown at src/mono/browser/runtime/marshal.ts:491
abstract class MemoryView implements IMemoryView {
protected constructor (public _pointer: VoidPtr, public _length: number, public _viewType: MemoryViewType) {
this._pointer = fixupPointer(_pointer, 0);
}
abstract dispose(): void;
abstract get isDisposed(): boolean;
_unsafe_create_view (): TypedArray {
if (this._viewType == MemoryViewType.Byte) {
return new Uint8Array(localHeapViewU8().buffer, this._pointer as any, this._length);
} else if (this._viewType == MemoryViewType.Int32) {
return new Int32Array(localHeapViewI32().buffer, this._pointer as any, this._length);
} else if (this._viewType == MemoryViewType.Double) {
return new Float64Array(localHeapViewF64().buffer, this._pointer as any, this._length);
} else if (this._viewType == MemoryViewType.Single) {
return new Float32Array(localHeapViewF32().buffer, this._pointer as any, this._length);
} else {
throw new Error("NotImplementedException");
}
}
set (source: TypedArray, targetOffset?: number): void {
mono_check(!this.isDisposed, "ObjectDisposedException");
const targetView = this._unsafe_create_view();
mono_check(source && targetView && source.constructor === targetView.constructor, () => `Expected ${targetView.constructor}`);
targetView.set(source, targetOffset);
// TODO consider memory write barrier
}
copyTo (target: TypedArray, sourceOffset?: number): void {
mono_check(!this.isDisposed, "ObjectDisposedException");
const sourceView = this._unsafe_create_view();
mono_check(target && sourceView && target.constructor === sourceView.constructor, () => `Expected ${sourceView.constructor}`);
const trimmedSource = sourceView.subarray(sourceOffset);
// TODO consider memory read barrier
target.set(trimmedSource);View on GitHub (pinned to 60108ba66e)
Solutions
- Confirm the MemoryView subclass was constructed with a valid MemoryViewType (Byte=0, Int32=1, Double=2, Single=3).
- If you extended MemoryViewType, add the corresponding branch to _unsafe_create_view in src/mono/browser/runtime/marshal.ts:491.
- If the value is being read from native/shared memory, verify the source buffer is not being overwritten out of band (thread race / buffer overrun).
Example fix
// before const view = new SomeMemoryView(ptr, len, 99); // invalid viewType // after const view = new SomeMemoryView(ptr, len, MemoryViewType.Int32);
Defensive patterns
Strategy: validation
Validate before calling
function isValidViewType(t: number): boolean {
return t === MemoryViewType.Byte
|| t === MemoryViewType.Int32
|| t === MemoryViewType.Double
|| t === MemoryViewType.Single;
}
// assert isValidViewType(view._viewType) before calling methods that build a TypedArray Type guard
function isKnownViewType(t: unknown): t is number {
return typeof t === 'number' && t >= 0 && t <= 3;
} Prevention
- Treat NotImplementedException from the marshaler as a bug - file it upstream rather than catching it.
- If you extend MemoryViewType, immediately update the switch in _unsafe_create_view.
- Avoid mutating the _viewType field after construction.
When it happens
Trigger: Constructing a MemoryView subclass instance whose _viewType field holds a value outside the 0..3 range of MemoryViewType, then calling set(), copyTo(), slice(), or any method that calls _unsafe_create_view(). Also reachable if the _viewType property is overwritten after construction.
Common situations: A new typed-memory-view variant is added to the marshaler enum but the switch in _unsafe_create_view is not updated; or an object's memory is misaligned/corrupted so the viewType byte reads as an unknown value. This is essentially never seen in normal API usage.
Related errors
- Argument to stringToInternedMonoStringRoot must be a string
- Unrecognized asset behavior:${asset.behavior}, for asset ${a
- event must be an object, but got ${JSON.stringify(event)}
- event.eventName is a required parameter, in event: ${JSON.st
- args must be an object, but got ${JSON.stringify(args)}
AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10).
Data as JSON: /api/errors/039a2f0e1e0f692a.
Report an issue: GitHub.