{"record":{"id":"dddc2073ca6b8327","repo":"dotnet/runtime","slug":"notimplementedexception-arraysegment-for-more-in-dddc20","errorCode":null,"errorMessage":"NotImplementedException: ArraySegment. For more information see https://aka.ms/dotnet-wasm-jsinterop","messagePattern":"NotImplementedException: ArraySegment\\. For more information see https://aka\\.ms/dotnet-wasm-jsinterop","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/marshal-to-cs.ts","lineNumber":406,"sourceCode":"                throw new Error(\"NotImplementedException: TypedArray\");\n            } else if (isThenable(value)) {\n                marshalTaskToCs(arg, value);\n            } else if (value instanceof Span) {\n                throw new Error(\"NotImplementedException: Span\");\n            } else if (jsType == \"object\") {\n                const jsHandle = getJsHandleFromJSObject(value);\n                setArgType(arg, MarshalerType.JSObject);\n                if (BuildConfiguration === \"Debug\" && Object.isExtensible(value)) {\n                    value[proxyDebugSymbol] = `JS Object with JSHandle ${jsHandle}`;\n                }\n                setJsHandle(arg, jsHandle);\n            } else {\n                throw new Error(`JSObject proxy is not supported for ${jsType} ${value}`);\n            }\n        } else {\n            assertNotDisposed(value);\n            if (value instanceof ArraySegment) {\n                throw new Error(\"NotImplementedException: ArraySegment. \" + jsinteropDoc);\n            } else if (value instanceof ManagedError) {\n                setArgType(arg, MarshalerType.Exception);\n                setGcHandle(arg, gcHandle);\n            } else if (value instanceof ManagedObject) {\n                setArgType(arg, MarshalerType.Object);\n                setGcHandle(arg, gcHandle);\n            } else {\n                throw new Error(\"NotImplementedException \" + jsType + \". \" + jsinteropDoc);\n            }\n        }\n    }\n}\n\nexport function marshalArrayToCs(arg: JSMarshalerArgument, value: Array<any> | TypedArray | undefined | null, elementType?: MarshalerType): void {\n    dotnetAssert.check(!!elementType, \"Expected valid elementType parameter\");\n    marshalArrayToCsImpl(arg, value, elementType);\n}\n","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/marshal-to-cs.ts#L388-L424","documentation":"Thrown by marshalCsObjectToCs when a value carries a GCHandle (i.e. it is a proxy created by C#) AND is an instance of the internal ArraySegment type, in the generic object marshaler. ArraySegment round-tripping through the object marshaler is intentionally not implemented; it must use the dedicated ArraySegment<T> marshaler.","triggerScenarios":"Receiving an ArraySegment<T> from one C# call and passing it into another C# method declared with `object` instead of ArraySegment<T>.","commonSituations":"Pooling/reusing ArraySegment instances across calls; declaring helper APIs with `object` parameters for flexibility, which routes them into the unsupported branch.","solutions":["Declare the C# parameter as ArraySegment<T> (e.g. ArraySegment<byte>) so the dedicated marshaler handles round-trip.","If a generic carrier is required, copy the segment's data (slice/copyTo) into a byte[] and pass that."],"exampleFix":"// before\nstatic partial void Sink(object value); // passing ArraySegment<byte>\n\n// after\nstatic partial void Sink(ArraySegment<byte> value);","handlingStrategy":"validation","validationCode":"function prepare(value: unknown): unknown {\n    if (value && typeof value === \"object\" && \"_pointer\" in value && \"array\" in (value as any)) {\n        throw new TypeError(\"ArraySegment must use the ArraySegment<T> marshaler, not object\");\n    }\n    return value;\n}","typeGuard":"const isArraySegmentLike = (v: unknown): boolean =>\n    !!v && typeof v === \"object\" &&\n    \"_pointer\" in (v as any) &&\n    typeof (v as any).copyTo === \"function\";","tryCatchPattern":null,"preventionTips":["Type ArraySegment-carrying parameters explicitly as ArraySegment<T>.","Avoid 'object' parameters on interop APIs that receive runtime-created proxies."],"tags":["marshaling","arraysegment","interop","type-mismatch"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}