{"record":{"id":"2730c3e70026a511","repo":"dotnet/runtime","slug":"notimplementedexception-span-2730c3","errorCode":null,"errorMessage":"NotImplementedException: Span","messagePattern":"NotImplementedException: Span","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/marshal-to-cs.ts","lineNumber":392,"sourceCode":"            } else if (value instanceof Float64Array) {\n                marshalArrayToCsImpl(arg, value, MarshalerType.Double);\n            } else if (value instanceof Float32Array) {\n                marshalArrayToCsImpl(arg, value, MarshalerType.Single);\n            } else if (value instanceof Int32Array) {\n                marshalArrayToCsImpl(arg, value, MarshalerType.Int32);\n            } else if (Array.isArray(value)) {\n                marshalArrayToCsImpl(arg, value, MarshalerType.Object);\n            } else if (value instanceof Int16Array\n                || value instanceof Int8Array\n                || value instanceof Uint8ClampedArray\n                || value instanceof Uint16Array\n                || value instanceof Uint32Array\n            ) {\n                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) {","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/marshal-to-cs.ts#L374-L410","documentation":"A JS value that is an instance of the interop Span type reached marshalCsObjectToCs in a context where the value has no managed gcHandle (i.e. it was not a Span handed back from C# to JS and then returned). Span is only meant to be marshaled via the explicit Span marshaler path (_marshalSpanToCs), not through the generic object converter.","triggerScenarios":"Constructing or obtaining a Span object in JS (e.g. from an earlier interop call that returned one) and then passing it back through a parameter/return typed as object or JSObject rather than as an explicit Span-typed marshaled argument.","commonSituations":"Storing a Span returned by one JSImport and passing it into another JSImport whose parameter is typed object; mixing Span with generic object marshaling signatures.","solutions":["Type the C# parameter/return as Span<T> (or the matching ref struct) so the value is routed through _marshalSpanToCs instead of the object marshaler.","Do not pass Span instances through object-typed interop boundaries; keep them on explicitly Span-typed signatures.","If you only need the bytes, copy the Span's contents into a Uint8Array/byte[] before crossing the object boundary."],"exampleFix":"// before - C#\n[JSImport(\"consume\", \"m\")]\nstatic partial void Consume([MarshalAs(typeof(object))] object span);\n\n// after\n[JSImport(\"consume\", \"m\")]\nstatic partial void Consume(Span<byte> span);","handlingStrategy":"type-guard","validationCode":"// Don't pass a Span through an object-typed boundary; copy out the bytes.\nimport { Span } from \"./marshaled-types\";\n\nfunction spanToBytes(s: Span): Uint8Array | null {\n  if (!(s instanceof Span)) return null;\n  return s.slice() as Uint8Array; // independent copy safe to marshal as byte[]\n}","typeGuard":"function isSpan(v: unknown): boolean {\n  return v instanceof Span;\n}","tryCatchPattern":"null","preventionTips":["Type C# interop params/returns as Span<T> so the value uses _marshalSpanToCs.","Never forward a Span instance through object-typed interop boundaries.","If only bytes are needed, copy the Span into a byte[] before crossing the boundary.","Keep Span instances within explicitly Span-typed call sites."],"tags":["jsinterop","marshaling","span","not-implemented"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}